On 05/12/2016 at 13:37, xxxxxxxx wrote:
Hi, I'm looking for a way to execute functions on the main thread from a different thread. I have found c4d.SpecialEventAdd, but it seems very limited. To pass custom parameters, it only allows for p1 and p2, which are both integers. How can I pass a string? Also, how do I get these parameters in the main thread?When I use MessageData.CoreMessage to handle the event, the bc parameter contains c4d.DA_VOID values which are PyCObjects. What am I supposed to do with these?
Any help is appreciated.
On 06/12/2016 at 02:28, xxxxxxxx wrote:
welcome to the Plugin Café forums
This question has been discussed several times in these forum.
A explanation how to receive the parameters in CoreMessage can be found in the How to identify different calls to CoreMessage? thread (see Yannick's answer). Also in SpecialEventAdd data thread.
A workaround to transfer float values (while losing precision) can be found in the SpecialEventAdd and Float parameter thread.
In order to transfer more complex data, we suggest to use some kind of global storage (in simplest form just a global variable). Store the data there before calling SpecialEventAdd() and then consume the data in CoreMessage(), possibly using the two integer parameters to identify the data.
On 06/12/2016 at 07:25, xxxxxxxx wrote:
Thank you Andreas,
I'll go with the global variable solution.
What's the best place to put in a feature request? The thing is, in almost every software I've used it's been so much easier to execute a function in the main thread. Maya, Nuke, and Houdini all have a function called executeInMainThreadWithResult which is so much simpler to use. PySide (Qt) as well has a really simple way to call a function in the main thread by using Signals and Slots. It would be great to have this in Cinema 4D without having to deal with PyCObjects and allowing to pass more complex data types than integers.
On 07/12/2016 at 02:17, xxxxxxxx wrote:
Actually you are at the best place you can be for any SDK related feature requests.
It is noted down.
Just want to add, that this is not in any case specific to our Python SDK, but it works the same in the C++ SDK (with the exception, that it's easy in C++ to mis-use the integer parameters as pointers to pass arbitrary information).
It shouldn't be too complicated to write a "ExecuteInMainThread" functionality yourself, even in Python. Maybe I find time during Christmas vacation. But maybe we can even make it a small Christmas contest? I have set up a thread for this here.
On 07/12/2016 at 07:04, xxxxxxxx wrote:
I was able to get an executeInMainThreadWithResult function working. I mostly copied Houdini's hdefereval module, so I don't know if it's okay to post it.
On 07/12/2016 at 07:34, xxxxxxxx wrote:
I'd rather not post code, which intellectual property is not clear.