Refresh Editor after killDocument or SetActiveDocument



  • 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!



  • 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



  • 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 :)