• Get All Assets in Category

    python
    3
    1
    0 Votes
    3 Posts
    993 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
    2k 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
    900 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
    392 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
    356 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
    786 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
    2k 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
    501 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
    404 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
    330 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
    498 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
  • How to select directories in a CUSTOMGUI_FILENAME?

    s26 python
    3
    0 Votes
    3 Posts
    760 Views
    P
    Hi @ferdinand , Thanks a lot, that's exactly what I was looking for ! flags: c4d.BaseContainer = c4d.BaseContainer() flags[c4d.FILENAME_DIRECTORY] = True # Add a CUSTOMGUI_FILENAME with our flags settings. self.AddCustomGui(id=MyDialog.ID_FILENAME, pluginid=c4d.CUSTOMGUI_FILENAME, name="Path", flags=c4d.BFH_SCALEFIT, minw=0, minh=0, customdata=flags)
  • Plug-in running fine on one OS but not another

    windows sdk
    13
    1
    0 Votes
    13 Posts
    2k Views
    Y
    @ferdinand Yes. it's solved. Thank you.
  • ActiveObjectManager_SetObject to display BaseObject in a GetListHead

    c++ sdk
    2
    0 Votes
    2 Posts
    467 Views
    ferdinandF
    Hello @kbar, Thank you for reaching out to us. This is a tricky one to answer, and my first instinct was that this is not too surprising due to what you do with your GeListHead, but the devil lies in the detail. In general, I would say that the safest route would be the one many of our implementations take: Displaying elements that are not part of the "standardized" branches of a scene graph via a DescriptionCustomGui wrapped by a custom GUI of yours which is part of a description of a (set of) node type(s) you provide. The FieldList data type/GUI does this for example. Overview Simply adding a custom branch in form of a GeListHead to a node of your choice will not make this custom branch discoverable via BranchInfo. This is because there is hard-coded data in the Cinema 4D core for this branch discovery. You can of course manually traverse the branches of your node. In the Attribute Manager SetObject implementation, this hardcoded branch structure is not being checked directly as far as I can see, but the Attribute Manger modes rely implicitly on it. You can register new Attribute Manger modes with ActiveObjectManager_RegisterMode which binds than that mode to a hook as for example shown in [1] (for materials in this case), see the MESSAGEHOOK documentation for details. It shows the case for tags as used internally. The object mode case is much more complex, but it will effectively fail on AOM_MSG_GETATOMLIST in your scene setup because the traversal done there assumes objects to appear in "object " branches only - which is not true in your case. Solutions I personally would still consider the DescriptionCustomGui route the safest way, especially because the GUI has the DESCRIPTION_OBJECTSNOTINDOC flag which allows you to also display orphaned nodes. Implement your custom attribute manager mode, which can deal with your custom scene traversal structure and mark your nodes with NBIT_ACTIVE so that the hook can find them. Regarding Xpresso nodes: They have their own branches which are respected in the AM implementation. As a warning: There are also quite a few hacks in the AM for Nodes API and shader nodes, especially regarding the traversal. In general, I would consider this non-regular scene structure of yours a problem with the AM because of how often Cinema 4D internally relies on a specific makeup of branches. It could very well be that you implement your AM mode, and everything will then work fine, but I cannot guarantee that. Which is a further point why I personally would gravitate towards the first solution. Cheers, Ferdinand [1]: static GeData MaterialMessageHook(const BaseContainer &msg, void *data) { switch (msg.GetId()) { case AOM_MSG_ISENABLED: return true; case AOM_MSG_GETATOMLIST: { BaseDocument *doc = GetActiveDocument(); if (!doc) break; doc->GetActiveMaterials(*((AtomArray*)data)); return true; } break; } return false; }
  • Can i get global input event ?

    python s26
    3
    0 Votes
    3 Posts
    417 Views
    gheyretG
    @ferdinand Wow~ Thank you so much bro
  • Get Node By Name?

    r25 python
    3
    0 Votes
    3 Posts
    377 Views
    B
    @Manuel Ah gotcha. It's only available R26 onwards. That's why I can't see something related in my R25 documentation.