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
    • Register
    • Login

    c4d.documents.SaveDocument modifies python source code file !!!

    Cinema 4D SDK
    r19 python
    3
    6
    1.6k
    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.
    • J
      jiceq
      last edited by r_gigante

      Hello,
      im facing a weird behaviour in cinema4d programming in python.

      im executing on demand via python's execfile function a custom script also written in python.
      This custom script imports the c4d module and does cinema 4d specific operations.
      the thing is, each time i run my execfile function that executes my custom script, this custom script file gets weirdly changed!! The source code is turned into what seems to be some kind of compiled version. Here is an image of the resulting file after execution:0_1536237281452_cinema4d.PNG

      Ive managed to narrow the cause of this source code modification to the method:
      c4d.documents.SaveDocument(active_doc, file_path, c4d.SAVEDOCUMENTFLAGS_0, c4d.FORMAT_C4DEXPORT)

      if i comment this method call and leave the rest of my custom script untouched the source file remains unchanged. So i think its pretty clear this method is doing something weird under the hood.

      Can someone spot what's going on?

      Im using Cinema 4D R19.

      Thanks in advance

      N 1 Reply Last reply Reply Quote 0
      • N
        NiklasR @jiceq
        last edited by

        @jiceq What's the value of file_path? Looks like you overwrite your script with a C4D scene file.

        1 Reply Last reply Reply Quote 0
        • J
          jiceq
          last edited by

          arghhh you were right, somehow i was mixing my custom script filepath with the cinema4d scene filepath!! Strange behaviour of cinema 4d is that it lets you save a file with any custom extension....

          Thanks Niklas.

          1 Reply Last reply Reply Quote 0
          • J
            jiceq
            last edited by

            Wait a minute!

            the filepath im passing to the SaveDocument() method was being correctly retrieved.

            i do this:

            file_path = os.path.join(c4d.documents.GetActiveDocument().GetDocumentPath(),c4d.documents.GetActiveDocument().GetDocumentName())

            Ive been using this method so far to retrieve the current cinema 4d scene pathname.Then i changed the overall behaviour of my application to run this custom script through an execfile() python method.

            Why is GetDocumentName()/GetDocumentPath() returning the filepath of my script file instead of Cinema's current scene name?

            Im relatively new to Cinema 4D... Am I retrieving incorrectly the scene name? What should i use instead?

            1 Reply Last reply Reply Quote 0
            • a_blockA
              a_block
              last edited by

              Hi,

              I'm not sure to be honest.
              Do you create the document with wrong path and name yourself?
              Can you maybe post some more code, so we can get a better idea, what's actually going on?

              Thanks,
              Andreas

              1 Reply Last reply Reply Quote 0
              • J
                jiceq
                last edited by

                Hi, thanks but i managed to fix it. It wasnt a Cinema4d related error. Apparently a bad argument to one of python methods was causing it to return the filepath of the script instead.

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