CommandData plugin catch Switching documents event
-
Hello everyone!
I trying to use this code from here to catch switching documents event with CommandData plugin Dialog.def Message(self, type, data): if type == c4d.MSG_DOCUMENTINFO: if data['type'] == c4d.MSG_DOCUMENTINFO_TYPE_LOAD: print ("Document holding object was set active") return True return TrueBut it's seems is not working in this case. Is it possible to know when user changes active document in case of CommandData plugin?
Thank you! -
Hello @mikeudin,
Thank you for reaching out to us.
But it's seems is not working in this case. Is it possible to know when user changes active document in case of CommandData plugin?
The posting you are referring to states that
"
MSG_DOCUMENTINFOis [...] a node message"A little bit more precise would be to say it is an atom message, i.e., it is only being sent to
C4DAtominstances viaC4DAtom.Message(). ACommandDataplugin is not an atom and its message method is part of another message stream.I would recommend having a look at the Python Message System Manual, as it lines out how messages work, and what kind of messages to expect in
CommandData.Message.Long story short, no, you will not find a message that signals the active document having been changed to a
CommandDataplugin. You will have to hook into other messages and manually check. The messages you could range from very broad asEVMSG_CHANGE(which is being broadcasted very often) to slightly more specific message IDs like, for exampleEVMSG_DOCUMENTRECALCULATED. I cannot tell you which one works best for your use case, I would have to try myself. Another approach would be to implement aNodeDataplugin and broadcast the information from there to yourCommandData. The problem is that Python lacks a goodNodeDatatype for that, as is lacks theSceneHookDatatype which would be the natural choice in C++. You can use some of the otherNodeDatatypes in Python likeObjectDataorTagData, but you should know that some atom messages are not being sent to all atoms, as Cinema 4D considers them irrelevant for these plugins.MSG_DOCUMENTINFOis one of these messages, and it is for example not being broadcasted toPreferenceData, which otherwise could serve as a replacement for aSceneHookData, as it is a node which has not to be instantiated as for example an object or tag must be.Cheers,
Ferdinand -
@ferdinand Thank you!