Add objects using Python Tag ?!
-
On 13/03/2018 at 04:19, xxxxxxxx wrote:
Hi all!
Based on some discussions I've read, including this:
https://developers.maxon.net/forum/topic/10624/14071_where-is-information-on-the-python-tag
I have gained great doubts on the following question:
I have a rather complex preset that uses several XPresso tags (so in my case it is not a plugin).
Needing to change the number of cloner object's children (I don't want to change the count attribute) in a simple and fast way, I inserted an user data button which is managed by the Python Tag. When the button is pressed, a dialog appears and it asks the user how many objects he wants, and by doing all the necessary checks it executes the command: it adds or deletes objects.
Everything seems to work correctly, but reading in the above discussion I understand that it is forbidden to add objects in this way.
I'm a little bit confused because I remember reading that to add or remove objects you should use at least a python tag.
How can I investigate the matter further? -
On 14/03/2018 at 06:39, xxxxxxxx wrote:
Hi,
there is a crucial detail, I probably should have explained better in the other thread.
The point is, you are not allowed to modify the scene during scene execution/evaluation. Neither in the execution (Execute()) nor in the drawing (Draw()) pipeline. For a tag this means, you are not allowed to do things like adding objects in Execute() or Draw() functions. And the main() function of the Python Script tag is being called within Execute() of a TagData.Now, you seem to have found out (I know, it shouldn't be needed to find out about such things, it should be properly documented...), that you can indeed implement a message(type, data) function (which will then be called during NodeData::Message()) inside of the Python Script tag in order to react for example to button presses. Totally fine. The message() function, at least in reaction to user interaction like button presses (MSG_DESCRIPTION_COMMAND), is not called during scene execution, but instead safely from the main thread. And with this explanation, you might already guess, where I'm heading, it is ok to create objects or modify the scene in other ways, as long as it is in reaction to user interaction from within the message() function.
-
On 14/03/2018 at 08:22, xxxxxxxx wrote:
Great!
This is the answer I wanted to read!Now, it is all much more clear.
Thank you man!Cheers,
Gianni