Maxon Developers Maxon Developers
    • Documentation
      • Cinema 4D Python API
      • Cinema 4D C++ API
      • Cineware API
      • ZBrush Python API
      • ZBrush GoZ API
      • Code Examples on Github
    • Forum
    • Downloads
    • Support
      • Support Procedures
      • Registered Developer Program
      • Plugin IDs
      • Contact Us
    • Categories
      • Overview
      • News & Information
      • Cinema 4D SDK Support
      • Cineware SDK Support
      • ZBrush 4D SDK Support
      • Bugs
      • General Talk
    • Unread
    • Recent
    • Tags
    • Users
    • Login

    Button 4d.MSG_DESCRIPTION_COMMAND [SOLVED]

    Scheduled Pinned Locked Moved PYTHON Development
    3 Posts 0 Posters 316 Views
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • H Offline
      Helper
      last edited by

      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...

      1 Reply Last reply Reply Quote 0
      • H Offline
        Helper
        last edited by

        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 😉

        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.

        1 Reply Last reply Reply Quote 0
        • H Offline
          Helper
          last edited by

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

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

          1 Reply Last reply Reply Quote 0
          • First post
            Last post