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

    SAVEDOCUMENTFLAGS_AUTOSAVE still added to the recent file list?

    Cinema 4D SDK
    windows python 2025
    2
    3
    544
    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.
    • D
      datamilch
      last edited by

      hi there,
      i recreated the autosave functionality (and tweeked the post-fix a bit) to be able to trigger it on demand.
      then i noticed the saved files still show up in the recent file list, even though i added the SAVEDOCUMENTFLAGS_AUTOSAVE flag. the documentation says this should not happen. adding SAVEDOCUMENTFLAGS_DONTADDTORECENTLIST makes it work.
      is this correct or a bug or something else wrong with my code?

      cheers sebastian

      import c4d, os, datetime
      
      doc: c4d.documents.BaseDocument  # The currently active document.
      op: c4d.BaseObject | None  # The primary selected object in `doc`. Can be `None`.
      
      def main() -> None:
      
          # autosave
          doc_path = doc.GetDocumentPath()
          doc_name = doc.GetDocumentName()
          now = datetime.datetime.now().strftime("%Y%d%m_%H%M%S")
          doc_name_post_fix = f"{doc_name}@export_{now}"
              
          prefs = c4d.GetWorldContainerInstance()
          ausosave_on   = prefs[c4d.WPREF_AUTOSAVE_ENABLE]
          ausosave_dest = prefs[c4d.WPREF_AUTOSAVE_DEST] # 0=project, 1=custom, 2=user
          if ausosave_on:
              if ausosave_dest==0:
                  if not doc_path:
                      #print( "no doc path, fallback to user" )
                      doc_path = c4d.storage.GeGetStartupWritePath()
                  save_path = os.path.join( doc_path, "backup", doc_name_post_fix )
              if ausosave_dest==1:
                  doc_path = prefs[c4d.WPREF_AUTOSAVE_DEST_PATH]
                  if not os.path.isdir(doc_path):
                      #print( "no custom path, fallback to user" )
                      doc_path = c4d.storage.GeGetStartupWritePath()
                      doc_path = os.path.join( doc_path, "backup")
                  save_path = os.path.join( doc_path, doc_name_post_fix )
              if ausosave_dest==2:
                  doc_path  = c4d.storage.GeGetStartupWritePath()
                  save_path = os.path.join( doc_path, "backup", doc_name_post_fix )
              #print( save_path )
              res = c4d.documents.SaveDocument(doc, save_path, saveflags=c4d.SAVEDOCUMENTFLAGS_AUTOSAVE | c4d.SAVEDOCUMENTFLAGS_DONTADDTORECENTLIST, format=c4d.FORMAT_C4DEXPORT)
              if not res:
                  print( "error writing autosave on export" )
      
      if __name__ == '__main__':
          main()
      
      ferdinandF 1 Reply Last reply Reply Quote 0
      • ferdinandF
        ferdinand @datamilch
        last edited by ferdinand

        Hey @datamilch,

        Thank you for reaching out to us and pointing this out. Your request has almost everything what makes a good request, executable code, and a contrast of what you think something should be and what is not working. But please provide instructions on how to use your code when required in the future. E.g., here 'expects a Cinema 4D instance with auto save enabled and a backup folder next to the saved current document'. I can of course read code to figure out why something is not working, but the more complex a code snippet gets, the greater the chance will be that we label something simply as "not executable" and not bother with finding out why a code example does not run on the first try.

        About your question: I had a brief look at our code base, and the auto save itself uses this instruction:
        54935c98-6cf7-4c61-adf9-b4a95fd23b73-image.png

        and the save handler then only checks for SAVEDOCUMENTFLAGS::DONTADDTORECENTLIST to determine if it should put a saved document into the recent list or not. So, I would say it is fairly safe to assume that our documentation simply degraded there a bit. I have removed the bit on SAVEDOCUMENTFLAGS_AUTOSAVE which talks about the recent file list.

        63a51785-7065-4f21-b700-574709f8e6bf-image.png

        So, TLDR, your script is the correct way to do it.

        Cheers,
        Ferdinand

        MAXON SDK Specialist
        developers.maxon.net

        D 1 Reply Last reply Reply Quote 0
        • D
          datamilch @ferdinand
          last edited by

          @ferdinand said in SAVEDOCUMENTFLAGS_AUTOSAVE still added to the recent file list?:

          But please provide instructions on how to use your code when required in the future.

          oh shit, i'm so sorry. you're right. completly missed this one. 😬
          ...
          and of cause thanks for the explaination / clarification.

          1 Reply Last reply Reply Quote 0
          • First post
            Last post