SOLVED Preventing SetDocumentData from switching to active tool

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

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

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

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?

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

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!