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

    Refresh Editor after killDocument or SetActiveDocument

    Cinema 4D SDK
    python windows r20
    2
    3
    619
    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 Boony2000

      Hi there!

      When trying to close a document via killDocument the Cinema window doesn't update the editor views, the object manager etc. until you click them. EventAdd() does not seem to do the trick.
      I also tried switching to a different document first via SetActiveDocument() to then kill the other document in the background, but it seems SetActiveDocument() has the same problem and does not automatically update the editor.

      What is the correct way to switch documents and have the editor show the new one?

      Thanks!

      1 Reply Last reply Reply Quote 0
      • S
        s_bach
        last edited by

        Hello,

        this code seems to work perfectly fine from a script:

        c4d.documents.KillDocument(doc)
        c4d.EventAdd()
        

        A new document can be created and inserted like this:

        newDocument = c4d.documents.BaseDocument()
        if newDocument is None:
            return
        
        c4d.documents.InsertBaseDocument(newDocument)
        c4d.documents.SetActiveDocument(newDocument)
        
        newDocument.SetDocumentName("new_document.c4d")
        
        c4d.EventAdd()
        

        Could you please share your code? How do you execute your code?

        best wishes,
        Sebastian

        MAXON SDK Specialist

        Development Blog, MAXON Registered Developer

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

          Hi Sebastian!

          Turns out my issues are two seperate, but equally self inflicted problems 🙂

          Inserting and activating works as expected, I am blocking the update with some custom UI stuff so I will have to find a solution for that. Calling EventAdd() in the closeEvent of the UI doesn't do anything. Is there another way to force Cinema to update everything?

          Killing the document not only doesn't update, but actually crashes Cinema, because I am trying to kill the document from within a callback that is reacting to MSG_DOCUMENTINFO_TYPE_LOAD. I am doing some more involved environment management and sometimes I have to close a document after loading.
          I have a workaround that will have to do for now. In the callback I change the document path to a string I can then look for in EVMSG_CHANGE. When I detect my string there, I can then kill the document. It's not very elegant and if anyone has a better solution I would be very happy, but otherwise consider this problem solved 🙂

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