Loading materials/meshes from Asset Browser (Cinema 4D R25) from Python
-
Hi,
As a part of an automated system, I load required materials and assets, when preparing the first version of a scene, from the Content Browser (Cinema 4D R23), using simple Python code (below, for materials)def LoadMaterial(location, name): doc = c4d.documents.GetActiveDocument() location = "preset://" + location + "/" + name status = c4d.documents.MergeDocument(doc, location, c4d.SCENEFILTER_MATERIALS) return status
As I understand the Content Browser have been replaced by Asset Browser, which looks much more powerful and I can't wait to start using it I can import all the assets from lib4d into R25 and access them manually, but I really need is the ability to load the assets from a code, as I do in r23. What's the best way of doing that? Can you provide me with a code snippet?
I basically want to have the same ability as in R23, wherein r25 I can pass DB name (or full path), together with object/mat name, and be able to download it to the scene. Also - is there a way to list all versions of an object or materials, and then choose one to download?
Best regards,
Tomasz -
Hello @futurium,
thank you for reaching out to us. The Asset API has unfortunately not been exposed to Python yet. We are working on it, and it will be released with one of the upcoming major releases. The C++ API is already available, but only partially documented right now. Its documentation is currently worked on too and will also be updated with one of the major upcoming releases.
Finally, regarding your sentence 'I can pass DB name (or full path), together with object/mat name': The Asset API works differently than the old Content Browser, as it is more fundamentally a (collection of) database(s) and not just a repository of files. The Asset API intentionally abstracts the physical view of one of its databases. So, when you have the database with the path
//user/documents/my_database
, you cannot search by the paths that are inside thatmy_database
directory, as the Asset API introduces virtual folders which are called categories and assets themselves. You can search by the URL of an asset, which then will of course reflect your local path, e.g.,//user/documents/my_database/some_asset_hash/1/asset.c4d
. The Asset API manages assets for you, and you are not meant to manually manage an asset location inside that database.The database topic of the Asset API C++ documentation already contains some information on the physical vs logical data model of the Asset API.
Cheers,
Ferdinand -
Hi Ferdinand,
Thank you for the explanation. Real shame the Asset API has not been exposed to Python yet. I'll wait till it's done and fully documented - let's hope it will be soon.
Best regards,
Tomasz -
Hello @Futurium,
without any further questions or postings, we will consider this thread as solved by Friday the 4th, February 2022.
Thank you for your understanding,
Ferdinand -
Hello Ferdinand,
I'm writing to revisit the issue previously discussed. Is there now Python support for this particular issue? Currently, I have a set of template materials in the Asset Browser. I have been loading them manually as required, which is manageable but not the most efficient method. It would be great if I could grab them directly from a script, preferably by their names. If name-based referencing isn't feasible, could I use their asset IDs instead?If this functionality is already in place, would you be able to share some code snippets? It would be greatly appreciated. Just for your reference, I'm currently using R26.107.
Best regards,
Tomasz -
Hello @Futurium,
Thank you for reaching out to us. Yes, the Asset API has matured by now, both in Python and C++. The Asset API documentation has been finalized with
S26
, so you should not have problems following it with yourS26
instance(s).You can find the Python code examples here, they reflect the code examples of the same name in C++. Of heightened interest is for you probably the LoadAssets example.
maxon.AssetManagerInterface.LoadAssets
will act like the Asset Browser, i.e., primarily load into the active document. When you want more control, you would have to implement manual asset loading as I have shown it in the C++ docs. Most Asset API assets are just c4d files, so there is not really a special source, it is just document loading and then pulling content out of that document (or just merge it as in your example).I would also recommend reading the C++ Asset API Manual, even for Python developers, as there are quite a few unique concepts in the API.
Cheers,
Ferdinand -
That's exactly what I was looking for. Thank you, Ferdinand