I want to refresh the dialog when switching documents. I tried to use the following code, but it seems that this cannot be achieved .
When I switch documents, it seems that I only receive type==c4d.MSG_COMMANDINFORMATION
def Message(self, type, data):
if type == c4d.MSG_DOCUMENTINFO:
if data['type'] == c4d.MSG_DOCUMENTINFO_TYPE_SETACTIVE:
Thanks for any help!
Thank you for reaching out to us. Your question is a little bit ambiguous as you do not clearly state what this message function of yours is a member of.
As explained in the Message System Manual, there are multiple types of message methods. Important in your specific use case is that there are two method 'groups' which have the general signature Message(a: int, b: typing.Any) -> bool, one attached to C4DAtom and one attached to GeDialog, GeUserArea and CommandData. There is a slight difference in their argument naming convention, but argument names do not carry any meaning here:
Message(a: int, b: typing.Any) -> bool
C4DAtom.Message(self, type, data=None) # This is a node message method.
NodeData.Message(self, node, type, data) # This is the node plugin hook counter part of it.
CommandData/GeDialog/GeUserArea.Message(self, msg, result) # This is a GUI/CommandData message method.
So, from the context - you said "I want to refresh the dialog" - I would assume you are implementing a GeDialog or CommandData and have there the code snippet you posted. Using the argument naming convention of C4DAtom.Message will do not any direct harm except for confusing an experienced C4D API reader, but you must understand that these are different methods which are called for different sets of events (i.e., message IDs). A GeDialog.Message will not be called for node events and a C4DAtom.Message will not be called for GUI events.
Inside a CommandData or GeDialog there is no dedicated message you can listen to for being notified about document changes (the whole MSG_DOCUMENTINFO message family is not being broadcasted to these methods). You must keep track of the active document yourself.
I have shown here what would be good pattern to implement such thing, at the slightly more complex case of tracking objects. The principal algorithm would be:
You must take this route over UUIDs, as nodes can be reallocated and destroyed, and you will then encounter false positives when you just store a BaseDocument in the lookup _activeDocUuid instead of its MAXON_CREATOR_ID hash. As shown in the lights example linked above, there are multiple levels of complexity you can implement this with, and for example implement _activeDocUuid as a list or hash map which tracks more than one thing.
I hope this helps and cheers,
@ferdinand Thanks for your help!