Button 4d.MSG_DESCRIPTION_COMMAND [SOLVED]

On 14/10/2016 at 03:39, xxxxxxxx wrote:

Hi All,

I am really struggling with the following. I tried some different versions but the all seem to give the same result:

Code:

class SETLIGHT(plugins.ObjectData) :
    def __init__(self) :
        self.SetOptimizeCache(False)
        
    def Message(self, node, type, data) :
        data = node.GetDataInstance()
        
        if type==c4d.MSG_DESCRIPTION_COMMAND:
            if data['id'][0].id==THE_BUTTON_ID:
                print "Pushed button with command ID", THE_BUTTON_ID
            return True       
if __name__ == "__main__":
    path, file = os.path.split(__file__)
    bmp = bitmaps.BaseBitmap()
    bmp.InitWith(os.path.join(path, "res", "Setlight.png"))
    plugins.RegisterObjectPlugin(id=PLUGIN_ID, str="Lights Controller",
                                g=SETLIGHT,
                                description="Setlight", icon=bmp,
                                info=c4d.OBJECT_GENERATOR)

Somehow I get the same error in my console:

Traceback(most recent call last) :
TypeError:__getitem__ expected int, not str

Can somebody help me and tell me what I'm doing wrong,
The code above comes form the maxons own sdk manual...

On 14/10/2016 at 08:38, xxxxxxxx wrote:

Hi,

At the beginning of Message() 'data' parameter is overwritten with the line:

data = node.GetDataInstance()

This assigns the object's container to 'data' variable and loose the actual value for the message data to process. Note the previous line doesn't come from the docs code snippet :wink:

Also, THE_BUTTON_ID should be an existing variable set to the integer parameter ID of the button to check.

I see the formatting in the code snippet for MSG_DESCRIPTION_COMMAND is broken. It will be fixed.

On 19/10/2016 at 02:04, xxxxxxxx wrote:

A real big thanx.
I feel a bit stupid but this solved the problem...