Saving Documents
-
From what I can see
c4d.documents.SaveDocument()
Does not work as expected - saving the active document to the given filepath and keeping the active document open under that "new" name/filepath.
It saves the document to disk at the given path and you must then load that new document from scratch and kill the previous one?
c4d.documents.SaveDocument(filepath) c4d.documents.LoadFile(filepath) c4d.documents.KillDocument(doc) # close the previous doc
Is this correct?
If you have a heavy file and are saving to a network location with python, every 'save as' action means reloading the entire scene from disk, which can be pretty slow/inefficient?
Is there a better method?
Thanks
-
Hello @Aeoll-0 ,
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
If I got your underlying idea right, you're trying to simulate the File -> Save Project behavior from python without any dialogs appearing. Please, correct me if I'm wrong.
The description to the c4d.documents.SaveDocument() function says:
Saves the document to a file.
Hence, I personally would not expect this function to behave as File -> Save Project.
If my understanding is right, then you're working with the active document in this context. In this case the following way could be the one of your choice:
doc: c4d.documents.BaseDocument = c4d.documents.GetActiveDocument() doc.SetDocumentPath(fileFolder) # e.g. fileFolder = "D:\\temp" doc.SetDocumentName(fileName) # e.g. fileName = "scene.c4d" c4d.CallCommand(12098) # Save Project
Another function that could help you here is the c4d.documents.SaveProject() one with the c4d.SAVEPROJECT_SCENEFILE flag:
c4d.documents.SaveProject(doc, c4d.SAVEPROJECT_SCENEFILE, fileFolder, [], [])
However, you only specify folder-path here, the resulting c4d-document will inherit the name from the folder name.
Let me know if there're any further questions!
Cheers,
Ilia -
Hi Ilia,
Thanks for the reply - you're correct about what I'm trying to do!
I've tried your first option and unfortunately the following dialog pops up:
"Unable to write file $FILE$ (file may be write protected)"
This dialog does not appear if the file is saved manually with the File -> Save Project As... Dialog
The save location is a network drive. Let me know if theres a workaround?
For your second option - is it possible to specify the exact filename here?
EDIT: It looks like you can also specify a filename here, which has worked - thanks !