UserData button

On 06/05/2014 at 15:20, xxxxxxxx wrote:

I created a button through UserData with:

UD=c4d.GetCustomDataTypeDefault(c4d.DTYPE_BUTTON)
UD[c4d.DESC_NAME] = "Press Me"
UD[c4d.DESC_CUSTOMGUI] = c4d.CUSTOMGUI_BUTTON
node.AddUserData(UD)

(actually, I created more than one button)

Now, how can I check what button was pressed.
I believe it is inside the Message method but... how?!

On 07/05/2014 at 02:43, xxxxxxxx wrote:

I think it is:
NodeData.Message(self, node, type, data)

MSG_DESCRIPTION_COMMAND Sent by for example BUTTON (description element). See [example](file:///D:/Users/pgrooff/Documents/pim/c4d/Python%20Help%20R15/help/modules/c4d.plugins/BaseData/NodeData/index.html#msg-description-command-example) below.

_<_t_>_

On 07/05/2014 at 03:43, xxxxxxxx wrote:

I had tried that but it returns me the same value, no matter what button I press 😞

I used this code to check it out:

def Message(self, node, type, data) :

if type==c4d.MSG_DESCRIPTION_COMMAND:
          bt = data['id'][0].id
          print bt

On 07/05/2014 at 07:55, xxxxxxxx wrote:

Here is how I do it in C++ (sorry).
I assume you already check this forum.
There are multiple posts about e.g. MSG_DESCRIPTION_COMMAND

Bool SolarObject::Message(GeListNode* node, Int32 id, void* data)
{
  
	switch (id)
      {        
        case MSG_DESCRIPTION_COMMAND:                                         // MSG_DESCRIPTION_COMMAND is send when button is clicked
        {            
            DescriptionCommand *dc = (DescriptionCommand* )data;               //data contains the description ID of the button           
            Int32 button = dc->id[0].id;                                       //Get the ID of the button
            //GePrint ("MSG_DESCRIPTION_COMMAND: " + String::IntToString(button));
  
            switch (button)    //Check for different button IDs
            {
                case SETKEY:		// set key

You can also try checking for MSG_DESCRIPTION_CHECKUPDATE

		case MSG_DESCRIPTION_CHECKUPDATE:                                         // MSG_DESCRIPTION_CHECKUPDATE is send UD field is clicked
        {            
			//BaseContainer *data = ((BaseObject* )node)->GetDataInstance();
			DescriptionCheckUpdate *dcu = (DescriptionCheckUpdate* ) data;
			Int32 button = dcu->descid[0][0].id; 

On 07/05/2014 at 07:58, xxxxxxxx wrote:

I don't understand why you can't get it's value just like any other UserData gizmo?

This script that will create a UD button to an object:

import c4d  
def main() :  
  
  obj = doc.GetFirstObject()  
  if not obj: return False  
  
  bc = c4d.GetCustomDatatypeDefault(c4d.DTYPE_BOOL)     #Create the default container  
  bc.SetString(c4d.DESC_NAME,"Click Me")                #The text on the button  
  bc.SetLong(c4d.DESC_CUSTOMGUI,c4d.CUSTOMGUI_BUTTON)   #Sets the bool gizmo to be a button  
  
  button = obj.AddUserData(bc)       #Add the userdata to the object  
  obj[button] = False                #Assign a default value to it when it created  
  
  c4d.SendCoreMessage(c4d.COREMSG_CINEMA, c4d.BaseContainer(c4d.COREMSG_CINEMA_FORCE_AM_UPDATE))  
  c4d.EventAdd()  
  
if __name__=='__main__':  
  main()

To get it's value this should be all you need to do.

  
  #Since the button gimzo was the first UD item created  
  #It has a level ID #1      
  btnValue = obj[c4d.ID_USERDATA,1]  #<---Returns true/false depending on the button's click state  
  print btnValue

Each new button should have it's own level#.
So you just use that number instead of #1 in the code for getting the value of the other buttons.

Are you doing something different than this Rui?

-ScottA

On 07/05/2014 at 11:08, xxxxxxxx wrote:

It worked great!! 🙂
Thank you, Scott.
I just had to make sure that after reading the value I set the value back to False.
Now I just need to know how to change the name of the UserData tab into another thing.
And, how to simulate multi-column groups of UD parameters programmatically.