• Reset Rotate With Compensate Points?

    Cinema 4D SDK r25 python
    4
    0 Votes
    4 Posts
    837 Views
    B
    For some fortunate happpenstance, found a code snippet that does this: https://gist.github.com/andreberg/885210
  • c4d.MatAssignData can't link.

    Cinema 4D SDK python windows
    4
    0 Votes
    4 Posts
    457 Views
    M
    Hello @Dunhou , without further questions or postings, we will consider this topic as solved by Thursday 01/06/2023 and flag it accordingly. Thank you for your understanding, Maxime.
  • Python Plugin GUI Tutorial

    Cinema 4D SDK python
    5
    0 Votes
    5 Posts
    2k Views
    J
    Thank you so much for the information. If further information is needed I will reopen this question.
  • Reset Scale With Compensate Points?

    Cinema 4D SDK r25 python
    3
    1
    0 Votes
    3 Posts
    679 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.
  • Python Cloner Effectors Keyframe

    Cinema 4D SDK python
    6
    1
    0 Votes
    6 Posts
    1k Views
    J
    I was able to solve it by searching the DescID in the Cloner Description with the Inheritance Name.
  • Mograph Objects Python

    Cinema 4D SDK python
    4
    0 Votes
    4 Posts
    686 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

    Cinema 4D SDK python
    3
    1
    0 Votes
    3 Posts
    914 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()
  • C4D Parent constraint python

    Cinema 4D SDK python
    14
    0 Votes
    14 Posts
    3k Views
    iplaiI
    @ferdinand Thanks, you are the best. This is exactly the internal operation I'm finding.
  • Paste JSON Values on the Node Network?

    Cinema 4D SDK 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?

    Cinema 4D SDK 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
  • A SetBit problem aka cann't select node.

    Cinema 4D SDK python windows
    5
    2
    0 Votes
    5 Posts
    554 Views
    DunhouD
    @ferdinand Thanks for the new solution for SetActiveObject . It works as expected. Much appreciated !
  • How to change bitmap in layered shader?

    Cinema 4D SDK python r19
    3
    0 Votes
    3 Posts
    1k Views
    V
    Perfect! Thank you so much!
  • How to Use ListAllNodes?

    Cinema 4D SDK r25 python
    5
    0 Votes
    5 Posts
    842 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
  • Append string the node path in retrieving the port?

    Cinema 4D SDK 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?

    Cinema 4D SDK r25 python
    3
    0 Votes
    3 Posts
    723 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.
  • Python tag wrong angle output in console

    Cinema 4D SDK python
    3
    2
    0 Votes
    3 Posts
    373 Views
    C
    Hi Ferdinand, Thanks for your in-depth answer! Cheers, Casimir Smets
  • Geometry Axis asset node and LoadAssets

    Cinema 4D SDK python s26
    7
    1
    1 Votes
    7 Posts
    1k Views
    M
    @Dunhou said in Geometry Axis asset node and LoadAssets: Hi there, In C4D 2024, the Geometry Axis can not accessible in python anymore, how can I fix that? from typing import Optional import c4d doc: c4d.documents.BaseDocument # The active document op: Optional[c4d.BaseObject] # The active object, None if unselected def main() -> None: for i, (bc, descid, _) in enumerate(op.GetDescription(c4d.DESCFLAGS_DESC_0)): name = bc[c4d.DESC_NAME] if name == "Axis X": print(i,descid) print(op[descid]) if __name__ == '__main__': main() 2024 [image: 1699255573905-832ba1ea-2683-4deb-95de-67444dbcf033-image.png] 2023 [image: 1699255607788-d37942ef-53b5-4e13-9cab-2946766c3fd6-image.png] Cheers~ DunHou Hi, this issue have been fixed in 2024.2 and your code is working as it was previously. Cheers, Maxime.
  • Normal Move command has no effect in R2023

    Moved Bugs python
    3
    0 Votes
    3 Posts
    800 Views
    bacaB
    @m_adam thanks!
  • 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.
  • Selection Order Flag for GetActiveMaterials?

    Cinema 4D SDK r25 python
    3
    0 Votes
    3 Posts
    318 Views
    B
    @Manuel Gotcha. Thanks for the confirmation.