Strip Texture Path using Python
-
Hello.
How can I remove the texture path from a project in c4d r17 using python, so that another person on his computer does not have to re-bind the texture path -
Hello @Djoneeeee,
Thank you for reaching out to us. I first must state that R17 is way out of the official SDK support cycle, which goes up to two versions prior to the current version, e.g., up to R23 for R25. We usually make some exceptions here and there, but I do not even have R17 currently installed on any machine, because it was released in 2014.
We could provide help for a more recent version, e.g., R20, which is similar in its principal architecture of using Python 2. But there is also the problem of the scope of your question:
- What constitutes as a texture path for you? It is not only materials which can reference images or videos as shaders, but there are also other entities, as for example a Relief Object or Shader Effector, which can hold textures.
- I assume you want to make these paths relative instead of absolute when you say "so that another person on his computer does not have to re-bind the texture path".
First of all, Cinema 4D has for quite a long time an already built-in feature for that, the Save Project with Assets ... command which will pack up the dependencies of a scene into a folder. I think this feature was already present with R17. In R21 we also introduced a tool to repair broken asset paths.
If you want to do this yourself, you must iterate over all nodes in the scene, then inspect their description, and search for base links of type
TEX
. For each of the parameter values you then must apply whatever you want to do with these paths. The topic has been discussed multiple times in the past, but can be tricky to implement when certain goals must be met.I also must point out that we cannot provide from-the-ground-up solutions here, you first must provide code with a specific question and we, the SDK-Team, will then provide answers for that coding problem.
Thank you for your understanding,
Ferdinand -
@ferdinand
I need to remove file paths only for textures.
manually, I only know this method:
Window -> Texture Manager
in Texture Manager: Edit -> Select All -> Relink Textures and Change your Computer Folder
But I don't know how to do it automatically without using the instructions above. If it’s not difficult, you can share code snippets, how you can save Project with Assets??I use this code to create textures:
userPath = # My PC Folder theNode = c4d.BaseList2D(c4d.Xbitmap) filename = # File Name if filename != None: theNode[c4d.BITMAPSHADER_FILENAME] = userPath + filename #theNode[c4d.BITMAPSHADER_FILENAME] = filename
When I use the script the textures have the given file format:
But I want to achieve this file format:
When manually adding a texture, this window appears:
which can regulate this, if there is a fragment to solve this problem, I will be grateful.
Thanks for Answer, will be wait feedback. -
Hello @djoneeeee,
the Texture Manger is not exposed in our APIs, so you cannot use it programmatically. I lined out the procedures you must employ when you want to write something like this from the ground up and we cannot provide the starting point for your code, this must be done by you, but we will help you along the way when you have questions.
You can invoke the Save Project with Assets ... command programmatically with c4d.documents.SaveProject(). There is also BaseDocument.GetAllTextures() which can be useful when you want to go with a more manual path.
Cheers,
Ferdinand -
Hello @djoneeeee,
without any further activity before Wednesday, the 16.03.2022, we will consider this topic as solved and remove the "unsolved" state from this topic.
Thank you for your understanding,
Ferdinand