Maxon Developers Maxon Developers
    • Documentation
      • Cinema 4D Python API
      • Cinema 4D C++ API
      • Cineware 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

    User Data - Get Button Name When Pressed

    PYTHON Development
    0
    3
    941
    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
      Helper
      last edited by

      On 11/05/2018 at 22:15, xxxxxxxx wrote:

      I have been using the following function to handle user data button presses:

      def message(id, data) :
          if id == c4d.MSG_DESCRIPTION_COMMAND:
              messageDataId = data["id"][0].id
              if messageDataId == c4d.ID_USERDATA:
                  userDataId = data["id"][1].id
                  if userDataId == 1:
                      print "button 1 pressed"
                  elif userDataId == 2:
                      print "button 2 pressed"
      

      Is there a way to get the button's name or short name from the message data or id?

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

        On 14/05/2018 at 07:01, xxxxxxxx wrote:

        Hi,

        welcome to the Plugin Café forums 🙂

        I assume you are implementing this inside of a Python generator or tag, right?

        In general parameters of objects (or tags, materials,...) are specified in so called Descriptions (also here). With User Data it's a bit special, as you first need to obtain the User Data containers, which store the Descriptions, via GetUserDataContainer().

        One more thing you need to know: In Python Generator and Tag there's a predefined global variable op, referencing the actual object (or tag).

        For example code could look like so:

        def message(id, data) :
            if id == c4d.MSG_DESCRIPTION_COMMAND:
                ud = op.GetUserDataContainer()
                for did, bc in ud:
                    if did == data["id"]:
                        print bc[c4d.DESC_NAME] + " pressed"
        
        1 Reply Last reply Reply Quote 0
        • H
          Helper
          last edited by

          On 14/05/2018 at 22:33, xxxxxxxx wrote:

          Hi Andreas,

          Thanks! That worked perfectly. 🙂

          Thanks for the explanation. I made several attempts to drill down into the User Data Container but couldn't figure it out.

          Thanks,
          Mike

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