User Data - Get Button Name When Pressed



  • 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?



  • 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"
    


  • 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


Log in to reply