Using MessagePlugin to signal CommandPlugin
-
On 08/02/2017 at 08:57, xxxxxxxx wrote:
Hi there,
I'm developing a C4D pipeline plugin for my studio that handles basic file management and organization by hooking into various project management databases. Not terribly exciting stuff, but it has to be done.
So far, I have a working CommandData plugin that handles the GeDialog interface, which is basically just a frontend to a library of Python scripts.
In the new version, one of the requests I'm hearing from artists is that they would like the GeDialog to refresh each time the user changes the active document (right now the GeDialog requires the user to manually refresh if they switch documents.)
A MessageData plugin seems like a viable option here. It would listen for a relevant "DocumentChanged" event and update the GUI as necessary.
The problem is, as usual, the Python documentation in C4D. I need a clearer understanding of how two plugins communicate with one another -- is the MessageData plugin wrapping the CommandData, or vice versa? Does the CommandData plugin listen for my custom MessageData plugin using some kind of EventHandler object I haven't come across?
I guess my question is fairly broad, which is why I haven't had any luck searching. I'm hoping I can be pointed in the right direction with some reference or examples. Any suggestions you can offer would be really helpful.
Thanks!
wt
-
On 08/02/2017 at 09:12, xxxxxxxx wrote:
You don't need another plugin.
Set a timer function into your gedialog.
In the gedialog store a class variable who will store the current doc.
Then in the timer get the active doc. If it's not the same then refresh the UI and update the variable which store the doc. -
On 08/02/2017 at 09:16, xxxxxxxx wrote:
It's simple to change and refresh the dialog when a button is pressed.
But it's more complicated to wait and verify that a new document was loaded. And will likely involve using a custom thread.If it was me. I would not bother checking if the new doc was loaded. And just update the dialog when a button is pressed if the document was actually found. Because I like to use the simplest solution with the least amount of code possible. And checking if the file exists should be good enough for 99.9% of cases.
The rare cases where the file is found but did not load would be so small that it won't be worth the time spent writing the code to handle it.-ScottA
-
On 08/02/2017 at 12:12, xxxxxxxx wrote:
You don't need another plugin.
Set a timer function into your gedialog.
In the gedialog store a class variable who will store the current doc.
Then in the timer get the active doc. If it's not the same then refresh the UI and update the variable which store the doc.This worked like a charm -- took all of 5 minutes once finding the right calls -- thanks for pointing me in the right direction!
I called self.SetTimer(500) in the GeDialog.CreateLayout() method, then set up my logic in the GeDialog.Timer() method.
For the record, here's the relevant bit in the docs:
https://developers.maxon.net/docs/py/2023_2/modules/c4d.gui/GeDialog/index.html?highlight=timer#GeDialog.SetTimer -
On 08/02/2017 at 12:25, xxxxxxxx wrote:
Thanks for the reply -- this wasn't so much a problem around confirming whether the scene loaded, but just finding a good way to get my UI to automatically trigger a refresh based on an external parameter. Turns out a timer works perfectly for this ...
-
On 09/02/2017 at 02:41, xxxxxxxx wrote:
Hi wtron,
welcome to the Plugin Café forums
... or you do not use a timer
In your GeDialog you can overload CoreMessage(), there you could listen to EVMSG_CHANGE, check if the active document changed and react accordingly by for example simply calling the InitValues() of your dialog.
In our C++ documentation there's the GeDialog manual, which also contains some more explanation and a code snippet on CoreMessage. I'm aware, it's not optimal we link to the C++ docs from the Python sub-forum all the time, but we can only improve things step by step.