R19 EventAdd() in tag workaround?
-
On 04/10/2017 at 03:17, xxxxxxxx wrote:
Hey there,
I hope this question is not too basic..
I searched the forums, but I cant find a proper workaround for using c4d.EventAdd() in a python tag.
I already tried DrawViews() as well as sending a dummy CoreMessage.This change seems to break a lot of scripts around the internet so it would be nice to have a proper, c4d plugin-developer-confirmed workaround
Thanks everyone
-
On 04/10/2017 at 04:09, xxxxxxxx wrote:
I suggest you to read https://developers.maxon.net/docs/py/2023_2/modules/c4d.threading/index.html?highlight=threading#threading-information.
SO no is not possible directly to add event inside a python tag.
Why? Simply because your python code is executed into[TagData.Execute()](https://developers.maxon.net/docs/py/2023_2/modules/c4d.plugins/BaseData/NodeData/TagData/index.html#TagData.Execute)
function so it's a threaded function.But what you can do is register another plugin. (MessagePlugin) and into your python tag send a message to your message plugin. And this one will run your code into the main thread.
For more information make sure to read
https://developers.maxon.net/forum/topic/9847/13260_christmas-competition-2016--executeinmainthread -
On 04/10/2017 at 04:53, xxxxxxxx wrote:
Oh I had a fear it would be like this.
Luckily we are running a company internal plugin-suite so it should be easy to add this function.Thank you
-
On 05/10/2017 at 04:03, xxxxxxxx wrote:
Hi,
As pointed out by gr4ph0s EventAdd() must not be called from within the execution pipeline.
The Python expressions (Python Tag, Generator, Effector and XPresso operator) are executed during such threaded process.
So it is forbidden to modify the active document and to call drawing functions for instance. See the Forbidden Functions.Expressions are executed after an event has been registered. So calling EventAdd() from such process adds again an event and ends up in a continuous update of a scene.
Since R19, using EventAdd() from within a Python expression does nothing.
If EventAdd() or any other forbidden function has to be called from an expression then the operations from within its code should be moved to a script/plugin executed in the main thread.