c4d.documents.SaveProject() preventing future save commands
-
C4D 2023
I am using the method in a custom script as follows:
c4d.documents.SaveProject(doc, c4d.SAVEPROJECT_SCENEFILE | c4d.SAVEPROJECT_ASSETS | c4d.SAVEPROJECT_USEDOCUMENTNAMEASFILENAME, self.filedir, [], [], )
When using this to save an open project to a different directory, the newly saved project file (which remains open in C4D) locks up and the user can no longer save the open project with Ctrl+S or File>Save Project.
An error dialog pops up showing:
Unable to write file "FILENAME" (file may be write protected)
There are no additional errors in the Console.
Any ideas? This is a blocker on our current pipeline.
-
Hello @Aeoll-0,
Thank you for reaching out to us. You should be a bit more specific about the circumstances and which you are using the command. As declared in our Support Guidelines, you should always post executable code, as we are otherwise are guessing what you are doing.
The
self.filedir
implies that this happens in a method, which in turn could mean that you are trying to do this off-main-thread. This is not allowed. I also gave it a spin myself, and for me it works.Note that after the operation, the opened file is not the old file anymore. So, when you had a
\data\a\myfile.c4d
and saved tobackup\a\
, the opened file will bebackup\a\myfile.c4d
and not\data\a\myfile.c4d
. Because of that, such newly "exported" documents will also induce thumbnail rendering. When you are trying to save many documents at once in this manner, the thumbnail rendering could make Cinema unresponsive. The path into which you want to dump things must also exist, Cinema 4D cannot create it for you.I have tested this in
2023.2.2
and2024.1.0
and found no problems in both versions.Cheers,
FerdinandResult:
Successfully saved project to: 'e:\projects\foo\', exporting the assets: [{'filename': 'e:\\projects\\foo\\myfile.c4d', 'assetname': 'myfile.c4d', 'channelId': 0, 'netRequestOnDemand': False}, {'filename': 'e:\\projects\\foo\\tex\\Maxon-Computer-Logo.jpg', 'assetname': 'E:\\temp\\Maxon-Computer-Logo.jpg', 'channelId': 0, 'netRequestOnDemand': True}].
Code:
import c4d import os doc: c4d.documents.BaseDocument # The active document def main() -> None: """ """ # Cinema 4D cannot create the directory path for us, we must ensure that #path does exist. path: str = "e:\\projects\\foo\\" if not os.path.exists(path): os.makedirs(path) # Your settings. flags: int = (c4d.SAVEPROJECT_ASSETS | c4d.SAVEPROJECT_SCENEFILE | c4d.SAVEPROJECT_USEDOCUMENTNAMEASFILENAME) data: list = [doc, flags, path, [], []] # Invoke the command and raise errors on failure or missing assets. if not c4d.documents.SaveProject(*data): raise IOError(f"Could not save project to: '{path}'.") if data[4]: raise IOError(f"Failed to export the following assets: {data[4]}") # Success :) print (f"Successfully saved project to: '{path}', exporting the assets: {data[3]}.") if __name__ == '__main__': main()
-