I made a simple python plugin for automated project generation in C4D 2023.1.3.
It basically loads a 3D model, creates a xRef that points to a master project file which includes all materials and then saves the document. The idea is, to have one file where I can edit materials, which automatically transfer to all my generated projects.
Everything works fine, except the xRef connection.
When I open my generated project, all xRef settings are greyed out and seem to have a broken file path (even though I inserted an absolute path, it displays just the filename). The weird thing is, that all the xRef materials and objects are imported successfully, but the connection to the file is lost and won't update. When I do it manually everything works as expected.
This post helped me a lot to set it up: https://plugincafe.maxon.net/topic/14319/does-xref-or-xref-simple-are-now-accessible-with-python
So my code looks like this (only the important parts):
# loading the master project doc = c4d.documents.LoadDocument("C:/path/to/master/project.c4d", c4d.SCENEFILTER_NONE) # creating the xref for the materials xref_materials = c4d.BaseObject(c4d.Oxref) doc.InsertObject(xref_materials) materialFileId = c4d.DescID(c4d.DescLevel(c4d.ID_CA_XREF_FILE, c4d.DTYPE_FILENAME, 0)) xref_materials.SetParameter(materialFileId, "C:/path/to/material/project.c4d", c4d.DESCFLAGS_SET_USERINTERACTION) c4d.EventAdd() # loading the 3d model c4d.documents.MergeDocument(doc, "C:/path/to/model.obj", c4d.SCENEFILTER_OBJECTS) # saving the project to another location c4d.documents.SaveDocument(doc, "C:/path/to/target/file.c4d", c4d.SAVEDOCUMENTFLAGS_NONE, c4d.FORMAT_C4DEXPORT)
I also tested different path formats like "file:///" and relative paths, but the problem persists.
Pre configuring the xRef in a seperate C4D project file and merging that into the current project, instead of creating the xRef directly, didn't work either.
Am I missing something?
Thank you very much for your help,