Buttons on Tag Plugins

THE POST BELOW IS MORE THAN 5 YEARS OLD. RELATED SUPPORT INFORMATION MIGHT BE OUTDATED OR DEPRECATED

On 24/05/2011 at 17:02, xxxxxxxx wrote:

Am I right that you can't use a button in the Execute Method of a tag plugin to do things like print. Or open a dialog message box?
I get illegal crossover errors when trying to do that.

In C++ I use the Message method to make button calls like this:

Bool MyTag::Message(GeListNode *node, LONG type, void *data)  
{  
  switch (type)  
    {          
      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             
          LONG button = dc->id[0].id; // get the ID of the button  
                        
          switch (button) // check for different button IDs  
          {  
              case BUTTON1:  
                  GePrint("Button1 was pushed");  
                  break;  
              case BUTTON2:  
                  GePrint("Button2 was pushed");  
                  break;  
          }  
      }  
    }  
  
  return TRUE;  
}

Am I supposed to do it that way in python too?
I don't think I saw any tags with buttons examples like this in the SDK.
Are there any examples of doing this with python?

-ScottA

THE POST BELOW IS MORE THAN 5 YEARS OLD. RELATED SUPPORT INFORMATION MIGHT BE OUTDATED OR DEPRECATED

On 24/05/2011 at 22:00, xxxxxxxx wrote:

Yes , it is possible.
Don't have the time now but in the afternoon (GMT+1) i can exactly tell you how.

It was something like:

  
def Message(op, data, type) :   
    if not data: return   
    id = data[0]['id'][0]   
    if id = MY_BUTTON_ID:   
        """ Stuff here """   

Maybe you can figure it out yourself with that sample. 🙂

Cheers, Niklas

THE POST BELOW IS MORE THAN 5 YEARS OLD. RELATED SUPPORT INFORMATION MIGHT BE OUTDATED OR DEPRECATED

On 25/05/2011 at 01:06, xxxxxxxx wrote:

I get illegal crossover errors when trying to do that.

Which function triggers that exception?

THE POST BELOW IS MORE THAN 5 YEARS OLD. RELATED SUPPORT INFORMATION MIGHT BE OUTDATED OR DEPRECATED

On 25/05/2011 at 07:35, xxxxxxxx wrote:

I think I was just using something simple like: if tag[1006]:gui.MessageDialog("Hello").
Or something similar to that.
But when I tried to get that same error happen again today. I can't make it happen.
When the button code wasn't working in the execute method. I tried a bunch of things, so lord knows what I did to trigger that error.😉

That's when I stopped messing around and looked up how I executed buttons in tags using C++.
And when I saw that I was doing it successfully inside of the Message method. I realized that I was probably putting my button code in the wrong place.

But now I need to figure out how to convert my C++ syntax to python.
Right now I'm trying this:

def Message(self, id, data, type ) :  
  
  if not data: return  
  
  id = data[0]['id'][0]  
  
  if id == CLICK_ME:  
print "Button Pushed"    
    
  return True

But I'm getting the error: "int" object is unsubscriptable. Traceback(most recent call last).
It looks like Rui and I are having the same problem.

-ScottA

THE POST BELOW IS MORE THAN 5 YEARS OLD. RELATED SUPPORT INFORMATION MIGHT BE OUTDATED OR DEPRECATED

On 25/05/2011 at 09:37, xxxxxxxx wrote:

I was now able to look it up, I used this.

  
def GetMessageID(data) :  
  try:  
      return data["id"][0].id  
  except:  
      return None

But I don't have the time to test it if its really working, sorry.

Cheers

THE POST BELOW IS MORE THAN 5 YEARS OLD. RELATED SUPPORT INFORMATION MIGHT BE OUTDATED OR DEPRECATED

On 25/05/2011 at 10:00, xxxxxxxx wrote:

Thanks for the help nux.
But I don't really understand the "try /except" thing very well yet.

I guess I need to see a very simple working example of a button used on a tag. Because I'm just not getting it.

-ScottA

THE POST BELOW IS MORE THAN 5 YEARS OLD. RELATED SUPPORT INFORMATION MIGHT BE OUTDATED OR DEPRECATED

On 25/05/2011 at 11:59, xxxxxxxx wrote:

Well, it's like try and catch. If anything goes wrong, there will be returned None instead an Error is raised.
I.e. if data is None, it's unsubscriptable. Or the data is different than the data when a button is clicked, that it may raise an error too.

THE POST BELOW IS MORE THAN 5 YEARS OLD. RELATED SUPPORT INFORMATION MIGHT BE OUTDATED OR DEPRECATED

On 25/05/2011 at 12:41, xxxxxxxx wrote:

I think I'm getting closer

def Message(self, tag, type, data) :  
  if type<>18: return True  
  button = data[c4d.CLICK_ME][0].id  
  if button == c4d.CLICK_ME: print("Button was Pushed");  
  c4d.EventAdd()  
     
  return True 

At this point. At least I get a result when I click the button.
But it returns this error: keyError: 1006   #1006 is the numerical ID for my button so that's working

-In C++. A description function is used to get the ID of a gizmo.
-Then that is assigned to a variable.
-Then that variable is used to point to the gizmo like this:  LONG button = dc->id[0].id;

I have converted everything to python except for the description function that C++ uses.
Maybe that's the missing piece to the puzzle?

-ScottA

THE POST BELOW IS MORE THAN 5 YEARS OLD. RELATED SUPPORT INFORMATION MIGHT BE OUTDATED OR DEPRECATED

On 26/05/2011 at 05:29, xxxxxxxx wrote:

I just don't understand what your problem is.
What are you doin with type != 18 ? And what's not working for you ? The function works as it should. It returns the current ID of the clicked element in the AM.

THE POST BELOW IS MORE THAN 5 YEARS OLD. RELATED SUPPORT INFORMATION MIGHT BE OUTDATED OR DEPRECATED

On 27/05/2011 at 13:59, xxxxxxxx wrote:

Here is an example of calling a button with python:

  
def GetMessageID(data) : #This custom method is used to get the id of your buttons  
  if data is None:  
      return  
  try:  
      return data["id"][0].id  
  except:  
      return  
  
  
class myTag(plugins.TagData) : #The tag class  
  
 def Init(self, tag) : # Set the default values for the tag's GUI elements  
  
  return True  
  
  
        
 def Message(self, op, type, data) :  
  doc = op.GetDocument()  
  id = GetMessageID(data)    #calls to the custom "GetMessageID()" method  
  if not id: return True     #Error handling  
    
  if id == c4d.CLICK_ONE:    #If the button named CLICK_ONE in your .res file is pressed  
  #Do Something  
  print "Button1 was Clicked"  
    
  if id == c4d.CLICK_TWO:    #If the button named CLICK_TWO in your .res file is pressed  
  #Do Something  
  print "Button2 was Clicked"      
    
  return True  
  
  
  
  
 def Execute(self, tag, doc, op, bt, priority, flags) :  
    
#Put your code stuff in here  
        
  return 0 

Thanks for the help Niklas. 🍺

-ScottA

THE POST BELOW IS MORE THAN 5 YEARS OLD. RELATED SUPPORT INFORMATION MIGHT BE OUTDATED OR DEPRECATED

On 27/05/2011 at 14:23, xxxxxxxx wrote:

Np 🙂
Did you see the example I've posted in Rui's thread ?

Btw, why do you use 1-space indentation ? The Python standart is 4 spaces.

Cheers,
Niklas

THE POST BELOW IS MORE THAN 5 YEARS OLD. RELATED SUPPORT INFORMATION MIGHT BE OUTDATED OR DEPRECATED

On 27/05/2011 at 17:19, xxxxxxxx wrote:

Yes. I saw it.
It helped me figure out what I was doing wrong.

I use single spacing because I hate python's indentation rules.
Actually. I more than hate it. But the word I really feel about it I can't say here or I'll get banned.😉
It's a lot easier for me to keep track of the indentation if I stay as close to the left margin as I can.
Rather than pushing everything four spaces out from the left margin.

I know it's bad form. But it helps me keep track of the empty spaces easier.
It also cuts down on how much swearing I do at my computer. 😂

-ScottA

THE POST BELOW IS MORE THAN 5 YEARS OLD. RELATED SUPPORT INFORMATION MIGHT BE OUTDATED OR DEPRECATED

On 28/05/2011 at 00:55, xxxxxxxx wrote:

Haha xD Hm, I actually like it. Because you can also just press Tab once and you've got 4 spaces in most editors. (Can be set in the preferences)
And it's a lot more overviewable. 🙂

-Niklas