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

    Preventing SetDocumentData from switching to active tool

    Cinema 4D SDK
    python r20 windows
    2
    5
    760
    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.
    • B
      Boony2000
      last edited by

      Hi!
      I am trying to change some stuff in reaction to the user changing settings.
      To do that I catch c4d.EVMSG_CHANGE and change some document settings via SetDocumentData.
      The problem I encountered is that SetDocumentData seems to switch the attribute editor to the active tool after it's done.
      That means I can't get to any other attributes, because e.g. selecting an object triggers SetDocumentData and switches back from the object settings to the tool.

      Maybe c4d.EVMSG_CHANGE is a little overkill to detect changes, but I don't know a better way.
      How do I stop SetDocumentData from switching what is shown in the attribute editor?
      Or if that's not possible how can I change something like the document framerate in reaction to something the user does?

      Thanks

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

        Hi,

        I cannot reproduce this on R20. I used the following code:

        import c4d
        
        # Main function
        def main():
            bc = c4d.BaseContainer()
            bc[c4d.DOCUMENT_FPS] = 42
            doc.SetDocumentData(c4d.DOCUMENTSETTINGS_GENERAL , bc)
            c4d.EventAdd()
        
        # Execute main()
        if __name__=='__main__':
            main()
        

        The attribute editor kept the document settings node selected. Could you shed some more light on your code / provide a snippet?

        If it is only the documents frame rate you are after, BaseDocument has the members GetFps() and SetFps().

        Cheers
        zipit

        MAXON SDK Specialist
        developers.maxon.net

        1 Reply Last reply Reply Quote 1
        • B
          Boony2000
          last edited by

          Interesting. What I was doing is this:

          doc = c4d.documents.GetActiveDocument()
          fps = 25
          docSettings = doc.GetDocumentData(c4d.DOCUMENTSETTINGS_GENERAL)
          docSettings[c4d.DOCUMENT_FPS] = fps
          doc.SetDocumentData(c4d.DOCUMENTSETTINGS_GENERAL, docSettings)
          

          Which does cause the problem even if directly entered via the python console.
          I don't know why that is bad exactly. At this point I was only changing the FPS, at another place a bunch of other stuff. It seemed logical to do it this way. Is using the get/set functions the better way to do that?

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

            Hi,

            when you overwrite all values of the general settings sub container, you also overwrite DOCUMENT_MODE (which probably causes the behavior you did encounter). You can just overwrite the specific values you need, like I have shown in my example.

            Cheers
            zipit

            MAXON SDK Specialist
            developers.maxon.net

            1 Reply Last reply Reply Quote 0
            • B
              Boony2000
              last edited by Boony2000

              I'm just going to go ahead and mark this as solved.
              Either using an empty Basecontainer or the set function solve the problem.

              Thank you for explaining!

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