using user data buttons in python [SOLVED]
-
On 21/08/2015 at 02:58, xxxxxxxx wrote:
Hi,
a Message() is nothing but a function call to a certain entity (objects, materials, tags,...), in order to notify it of some change. There are a lot of different messages, differentiated by their type/ID. Each message can provide data, which in the C++ API comes in a special structure. Often this structure then also contains a BaseContainer with further information. Depending on the type of a message, the structure and content of such a BaseContainer differ.
Now, in Python, the structure is mapped into a dictionary. That's the strange syntax (data['id']), which simply returns the value for the keyword "id" from the data dictionary.Here the ID/type of the message we are looking for is c4d.MSG_DESCRIPTION_COMMAND. It's mainly used for button presses (but not restricted to these).
Then normally (I mean, in a standard description of for example an object) data['id'][0].id contains the ID of the description parameter (which could already be your button). But with User Data it's a tiny bit more complicated. As you get the c4d.ID_USERDATA here, which tells you, that you get the MSG_DESCRIPTION_COMMAND for a User Data parameter. I'm sorry, I assigned this to id in my first example (it's already corrected), it was a mistake (even though no bug). Didn't want to confuse you.
So for User Data you need to go one level deeper, in order to also find out the actual User Data ID (with data['id'][1].id).
And now, finally, why it is not working in your case:
As said in the beginning a message is sent to an object or tag. But it is no broadcast, it is send directly to one entity. You create User Data on a cube and have a script on an interaction tag. That won't work.
The solution would be to have the buttons on the the Interaction tag (which I assumed, when writing my first answer in this thread). -
On 21/08/2015 at 04:21, xxxxxxxx wrote:
thank you very very much for the detailed explaination, it's much clearer now
-
On 21/08/2015 at 04:33, xxxxxxxx wrote:
You are welcome.
Actually I forgot to provide the link, as it is actually documented in the Python SDK Docs:
MSG_DESCRIPTION_COMMAND exampleEdit: Updated link
-
On 15/09/2015 at 02:17, xxxxxxxx wrote:
Hi,
I'm trying this example out, but I can't get it to work :s
Getting inside the message is no problem, but as soon as I check if it's a command, my code fails, I guess.It's inside a python tag, and my button is on the tag and on the object as well (for testing purposes).
Here is my code:
def message(id, data) : print "Inside Message" if id == c4d.MSG_DESCRIPTION_COMMAND: print "Clicked"
"Inside Message" gets printed everytime I click, yet "Clicked" never gets printed.
Does anybody have an idea what could be the problem here?
Thanks in advance for your help and time!
-
On 15/09/2015 at 03:45, xxxxxxxx wrote:
Hi,
Well, apparently, my data is empty, so the id becomes MSG_MULTI_MARKMATERIALS.
"When data is None this is sent to plugin nodes to let them mark the materials that they use. Otherwise the message is sent to let you translate you material links, for example when a material is replaced, and then the corresponding structure is MarkMaterials. (An example for both cases is included on the MarkMaterials page.)"
-
On 15/09/2015 at 05:19, xxxxxxxx wrote:
Hi,
So, it's only possible to use this in the interaction tag?
No way at all for doing it inside a python tag?Thanks for your help and time!
-
On 15/09/2015 at 09:36, xxxxxxxx wrote:
Hi Casimir,
no, the Python Tag currently does not support UserData buttons. Sorry.
-
On 15/09/2015 at 10:02, xxxxxxxx wrote:
Hi Andreas,
Okay, thanks for your answer!
I'll just hide some of the properties of the interaction tag (shown in the object), then.
-
On 02/11/2015 at 10:56, xxxxxxxx wrote:
Hi,
please forgive my stupidity. While the Python tag does indeed not support the standard way of processing buttons, Cairyn came up with a nice solution for the Python tag in this thread about Rename by adding a digit at the end. He makes use of MSG_DESCRIPTION_CHECKUPDATE, which works really nice. Sorry, I didn't come up with that solution earlier.
-
On 03/11/2015 at 01:21, xxxxxxxx wrote:
Hi Andreas,
Thanks for the information!!
And no problem, you have a lot to think about