Maxon Developers Maxon Developers
    • Documentation
      • Cinema 4D Python API
      • Cinema 4D C++ API
      • Cineware API
      • ZBrush GoZ API
      • Code Examples on Github
    • Forum
    • Downloads
    • Support
      • Support Procedures
      • Registered Developer Program
      • Plugin IDs
      • Contact Us
    • Categories
      • Overview
      • News & Information
      • Cinema 4D SDK Support
      • Cineware SDK Support
      • ZBrush 4D SDK Support
      • Bugs
      • General Talk
    • Unread
    • Recent
    • Tags
    • Users
    • Login

    c4d.documents.SaveProject() preventing future save commands

    Cinema 4D SDK
    2023 python
    2
    2
    560
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • A
      Aeoll 0
      last edited by

      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.

      ferdinandF 1 Reply Last reply Reply Quote 0
      • ferdinandF
        ferdinand @Aeoll 0
        last edited by ferdinand

        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 to backup\a\, the opened file will be backup\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 and 2024.1.0 and found no problems in both versions.

        Cheers,
        Ferdinand

        Result:
        34f18c02-cc1d-42ef-94ac-d50f2ad57195-image.png

        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()
        

        MAXON SDK Specialist
        developers.maxon.net

        1 Reply Last reply Reply Quote 0
        • maxonM maxon referenced this topic on
        • First post
          Last post