xRef file path is broken if created via python
-
Hello,
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://developers.maxon.net/forum/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,
David -
@BackendKG Hello @user,
Welcome to the Plugin Café forum and the Cinema 4D development community, it is great to have you with us!
Getting Started
Before creating your next postings, we would recommend making yourself accustomed with our Forum and Support Guidelines, as they line out details about the Maxon SDK Group support procedures. Of special importance are:
- Support Procedures: Scope of Support: Lines out the things we will do and what we will not do.
- Support Procedures: Confidential Data: Most questions should be accompanied by code but code cannot always be shared publicly. This section explains how to share code confidentially with Maxon.
- Forum Structure and Features: Lines out how the forum works.
- Structure of a Question: Lines out how to ask a good technical question. It is not mandatory to follow this exactly, but you should follow the idea of keeping things short and mentioning your primary question in a clear manner.
About your First Question
You said that you
[...] made a simple python plugin for automated project generation in C4D 2023.1.3.
What do you mean by that? Are you using
c4dpy
or are you usingCinema 4D
? When I run my code from the old thread, I do not have any problems crating suchXref
, saving it as a file, and loading that file back.- Please share which application you are using.
- Please share executable code, in your snippet at least the import statements are missing.
- Check if your file paths are correct. You use there forward slashes for a Windows path which should work, but it is better to escape paths when you write them manually. E.g.,
r"e:/test.c4d"
or"e://test.c4d"
. Finally, you could also make sure that your Urls are being interpreted as being in the file scheme withr"file:///e:/test.c4d"
.
When you use
c4dpy
, you probably have to execute the passes on that document before saving it, or do some message magic, given how custom Xrefs are with being bound to the GUI in form ofDESCFLAGS_SET_USERINTERACTION
. Or in the worst case, it might be impossible to create Xref instances in a headless Cinema 4D instance, i.e.,c4dpy
.Cheers,
Ferdinand -
Sorry for not making my post as clear as it should have been, next time I will do better
The good thing is, I fixed it! The problem was how I loaded my initial master project.
# instead of using c4d.documents.LoadDocument() # i replaced it with c4d.documents.LoadFile()
... and now my xRef works just fine!
Thank you again!