• Reset Scale With Compensate Points?

    r25 python
    3
    1
    0 Votes
    3 Posts
    682 Views
    B
    @m_adam Gotcha. Thanks for the response. It works but I was kinda looking for the thought process on how to implement it. Mainly because the command is only limited to scale. I was hoping I can modify it to include also rotation.
  • PYTHONPATH not appended to sys.path in Cinema 4D 24

    s24 python
    6
    0 Votes
    6 Posts
    1k Views
    F
    Excellent! Thanks you a lot Regards,
  • A SetBit problem aka cann't select node.

    python windows
    5
    2
    0 Votes
    5 Posts
    555 Views
    DunhouD
    @ferdinand Thanks for the new solution for SetActiveObject . It works as expected. Much appreciated !
  • C4D Parent constraint python

    python
    14
    0 Votes
    14 Posts
    3k Views
    iplaiI
    @ferdinand Thanks, you are the best. This is exactly the internal operation I'm finding.
  • Mograph Objects Python

    python
    4
    0 Votes
    4 Posts
    708 Views
    ferdinandF
    Hello @joel, Thank you for reaching out to us and thank you @iplai for providing the answer. There is not much to add for us here. Prior to 2023.0.0 there were some larger gaps in the type symbol definitions of classic API nodes, e.g., objects, tags, materials, shaders, Xpresso nodes, scene hooks, etc, because they were never defined in the frameworks (so this was not just a Python thing, even in our internal C++ API they were more or less hardcoded). One major offender was your use case, MoGraph. With 2023.0.0 I have added the cases which I considered most important for public users, objects, materials, shaders, tags and Xpresso nodes. But there are still some gaps in more fringe node types as for example scene hooks, because it is quite a bit of work to pull them out of our code base. With that being said, a type symbol is just that: a symbol. They stand for the integer ID with which the type is being registered. You can always use the raw integer value or just define a symbol for the integer value yourself. import c4d # Define the two symbols yourself and attach them to the c4d module. c4d.Omgcloner: int = 1018544 c4d.Omginheritance: int = 1018775 def main(): """ """ a: c4d.BaseObject = c4d.BaseObject(c4d.Omgcloner) b: c4d.BaseObject = c4d.BaseObject(c4d.Omginheritance) if None in (a, b): raise MemoryError("Object allocation failed.") doc.InsertObject(a) doc.InsertObject(b) c4d.EventAdd() if __name__ == "__main__": main() An uncomplicated way to find out these type symbols is the console and the method C4DAtom.GetType (all classic API nodes are of type C4DAtom). Drag the thing you are interested in into the console (e.g., the Inheritance object) and type after it .GetType() and press Enter: [image: 1668067076009-gettype.gif] Cheers, Ferdinand
  • Get All Assets in Category

    python
    3
    1
    0 Votes
    3 Posts
    923 Views
    ferdinandF
    Hello @d_keith, thank you for reaching out to us and your extensive documentation efforts. Much appreciated! What you did there is correct, but in the spirit of simplicity, I think the code could be a bit condensed. There snuck in a few unused (and unrelated) includes and being so generous with separating things into help functions can impact readability and execution times. I also added the "expand asset category into sub-categories" thing you wanted. In short: I think this is a good occasion to use a receiver callback function, as this structures the code naturally. Find my take below. Cheers, Ferdinand The result: categoryIds = [maxon.Id('category@b9c32d04a12d449ca1c758ddb3c695b0'), maxon.Id('category@985a9913c47341e4a373ca71d8e73b18')] name = 'Cloudy - VHDRI.hdr', asset.GetId() = 'file_e02d0a81b02be4fa' name = 'Default HDR.hdr', asset.GetId() = 'file_2792c7829905f40d' name = 'Desert.exr', asset.GetId() = 'file_0b3eb8e7595c1b5d' name = 'jhdri-v1_ext_sunset_seastar_acescg.exr', asset.GetId() = 'file_dc156adf0cc146e8' name = 'HDR012.hdr', asset.GetId() = 'file_b1db2c38badb130c' The code: """Retrieves all MediaImage assets that are attached to the "Textures/HDR" category or one of its child categories. This is an application of what I dubbed "Filtered Asset searches" in the C++ Docs, find the Python example here [1]. References: [1] https://github.com/PluginCafe/cinema4d_py_sdk_extended/blob/master/scripts/05_modules/assets/asset_databases_r26.py#L416 """ import typing import maxon def ExpandAssetCategoryId(repo: maxon.AssetRepositoryInterface, cid: maxon.Id) -> list[maxon.Id]: """Retrieves the IDs of all descendant asset categories of #cid. """ # Get all asset category assets in #repo. categoryAssets: maxon.AssetDescription = repo.FindAssets( maxon.AssetTypes.Category(), maxon.Id(),maxon.Id(), maxon.ASSET_FIND_MODE.LATEST) # The IDs we have currently to check for descendants and the final result list. idsToCheck: list[maxon.Id] = [cid] results: list[maxon.Id] = [] # Try to empty #idsToCheck while popping elements from it and adding new ones. while idsToCheck: # Remove the first element and add it to the results. cid: maxon.Id = idsToCheck.pop() results.append(cid) # Find all category assets which have #cid as their parent category and add their IDs as # to be resolved category IDs. We stop the search here early, i.e., we assume the category # tree to be mono-hierarchical (one category can only be attached to one category). There # is not really anything in the Asset API which would enforce this, but it is how asset # categories are currently handled. for asset in categoryAssets: if cid == maxon.CategoryAssetInterface.GetParentCategory(asset): aid: typing.Any = asset.GetId() idsToCheck.append(aid if isinstance(aid, maxon.Id) else maxon.Id(aid)) break return results def main() -> None : """Runs the example. """ # Make sure the asset databases have been loaded and get the user repository, i.e., the # repository where more or less all content can be found. if not maxon.AssetDataBasesInterface.WaitForDatabaseLoading(): raise RuntimeError("Could not load asset databases.") repo: maxon.AssetRepositoryRef = maxon.AssetInterface.GetUserPrefsRepository() if not repo: raise RuntimeError("Unable to retrieve user repository.") # The final #results list where we put all the asset descriptions of image assets which are # parented to category assets with any of the IDs in #categoryIds. results: list[tuple[str, maxon.AssetDescription]] = [] # The root category we are interested in, this is the id for the "Textures/HDR" category. rootCategoryId: maxon.Id = maxon.Id("category@b9c32d04a12d449ca1c758ddb3c695b0") # Expand #rootCategoryId into a list of all its attached child categories. categoryIds: list[maxon.Id] = ExpandAssetCategoryId(repo, rootCategoryId) # The language Cinema 4D is running in, use GetDefaultLanguage() to evaluate things in engUS. currentLanguage: maxon.LanguageRef = maxon.Resource.GetCurrentLanguage() def onSearchHit(asset: maxon.AssetDescription) -> bool: """Called for each asset by the FindAssets() call below. Assets which match the search criteria are written to #results. """ # Get the metadata of the asset and assert that its subtype is MediaImage, step over an asset # when these operations fail. metadata: maxon.AssetMetaData = asset.GetMetaData() if metadata is None: return True sid: maxon.InternedId = maxon.InternedId(metadata.Get(maxon.ASSETMETADATA.SubType, maxon.Id())) if sid != maxon.ASSETMETADATA.SubType_ENUM_MediaImage: return True # Append the name of the asset and the asset itself to the results when #asset is parented # to a category asset with an ID which is contained ins #categoryIds. if maxon.CategoryAssetInterface.GetParentCategory(asset) in categoryIds: results.append((asset.GetMetaString(maxon.OBJECT.BASE.NAME, currentLanguage, ""), asset)) return True # Search #repo for all file type assets (this includes MediaImage assets) with any id and pass # the data through onSearchHit. repo.FindAssets( assetType=maxon.AssetTypes.File(), aid=maxon.Id(), version=maxon.Id(), findMode=maxon.ASSET_FIND_MODE.LATEST, receiver=onSearchHit) # Print the expanded category IDs and the first five asset matches associated with them. print (f"{categoryIds = }") for name, asset in results[:5]: print (f"{name = }, {asset.GetId() = }") if __name__ == "__main__": main()
  • Paste JSON Values on the Node Network?

    r25 python
    7
    0 Votes
    7 Posts
    1k Views
    B
    @iplai ah yep. I'll probably use this one since it does not require third party library. haha. Thanks for the illustration!
  • Get the Name of the Node?

    r25 python
    7
    0 Votes
    7 Posts
    1k Views
    M
    You have to be careful since the value returned by effectivename will change according of the Cinema 4D language. The best way is really to work with IDs. Cheers, Maxime
  • How to Use ListAllNodes?

    r25 python
    5
    0 Votes
    5 Posts
    845 Views
    ferdinandF
    Hello @bentraje @bentraje said in How to Use ListAllNodes?: doc: c4d.documents.BaseDocument # The active document. I'm not too familiar with the Python 3 syntax but this line returns an empty graph down the line. Tha is a bit odd, especially since I tested and ran the code with R25. This line or code such as below # Without type hinting. def foo(a): return f"{a}" # With type hinting. def foo(a: typing.Any) -> str: return f"{a}" makes use of type hinting. It tries to rectify ambiguities that come with the fact that Python is dynamically typed. For now, type hinting has no real impact on code run on CPython (i.e., the "standard" Python), unless you use special libraries to run your CPython code or use interpreters other than CPython which support static or at least asserted typing out of the box. All the line doc: c4d.documents.BaseDocument # The active document. does for now is: Make code more readable by telling humans what the module attribute doc is and that it exists in the first place. Enable auto-complete engines as provided by, for example, VSCode to give you smart suggestions. Enable linters or runtime libraries to run type assertions on your code. Adding or removing this line should have zero impact on the execution, unless you added there an equals sign and overwrote the value of doc. Cheers, Ferdinand
  • How to change bitmap in layered shader?

    python r19
    3
    0 Votes
    3 Posts
    1k Views
    V
    Perfect! Thank you so much!
  • Python tag wrong angle output in console

    python
    3
    2
    0 Votes
    3 Posts
    373 Views
    C
    Hi Ferdinand, Thanks for your in-depth answer! Cheers, Casimir Smets
  • How to render a animation preview ?

    sdk s26 python
    7
    0 Votes
    7 Posts
    1k Views
    M
    Hi @Dunhou you can't control the Make Preview plugin, you have to rewrite the function yourself with all the tips previously shared in this topic. Cheers, Maxime.
  • Append string the node path in retrieving the port?

    python r25
    3
    0 Votes
    3 Posts
    338 Views
    B
    @ferdinand Thanks for the clarification and offering some alternatives. I guess it has something do with how it was designed. There is a FindChild equivalent in other DCC API too like in maya there is a GetAttr or something. But again, if you know the actual parameter/attribute path like texturenode.tex0.colorspace texturenode.uv.uv_channel texturenode.remape.scale.x There's no need. It's straightforward. You use that instead. Anyhow, will close this thread now.
  • API for Project Asset Inspector?

    r25 python
    3
    0 Votes
    3 Posts
    729 Views
    B
    @ferdinand Thanks for the response. RE: we never expose managers themselves Gotcha. Thanks for the clarification RE: Code Works as expected. Closing this thread now.
  • Change the ColorSpace of Redshift Texture Node?

    r25 python
    6
    1
    1 Votes
    6 Posts
    1k Views
    B
    @Dunhou @Manuel Thanks for the response. I ended up going for the ctrl+C on the node editor Pretty straightforward and works as expected. Functions like how you copy/paste nodes on Fusion and Nuke.
  • Creation of UVW tag for a plane

    Moved
    2
    1
    0 Votes
    2 Posts
    474 Views
    ManuelM
    hi, you can use CallUVCommand. The forum also has different thread already talking about it. This one for example, explain how to use command to pack your UVs. It shows how to automatically unwarp your model and answer what you are looking for. This is done using SendModelingCommand with some parameters, those parameters can be found here in the c++ documentation. Of course, you can also create the uvw tag yourself and define the uvw coordinates as you wish. You have this thread for example that shows how to do a planar projection. Cheers, Manuel
  • Python scripting tag editing object position and points

    python
    3
    0 Votes
    3 Posts
    371 Views
    C
    Hi Ferdinand, Thanks a lot for your in-depth answer! I was assuming it was possible, but now I know for sure! Cheers, Casimir Smets
  • Selection Order Flag for GetActiveMaterials?

    r25 python
    3
    0 Votes
    3 Posts
    318 Views
    B
    @Manuel Gotcha. Thanks for the confirmation.
  • String values for the "FindChild"?

    python r25
    13
    0 Votes
    13 Posts
    1k Views
    B
    @Manuel Gotcha. Thanks for the clarification. Sorry for the trouble. Works as expected. Will close this thread now.
  • Set c4d.InExcludeData() has something didn't expect.

    s26 python windows
    3
    0 Votes
    3 Posts
    471 Views
    DunhouD
    @ferdinand Thanks for that solution. It's happy to hear that , I do try to make win-win clear post as I can to don't waste our time , hope it's a worthy work I tested the new GetUpdatedInexcludeData function , it worked well , The "click twice" thing never happen again . It's the None condition I didn't realize before . It does happend when no or single object in the list . And for the "odd place" and the "exception ", it is a test to make sure all the things above work well( after that are all the settings ) . I forgot move to the right place . sorry to that Thanks for the caring code for c4d.utils.DegToRad(360) , I haven't notice this before and just stupid import radians