Plugin Cafe Homepage
Forum Home Forum Home > Plugin Cafe > PYTHON Development
  New Posts New Posts
  FAQ FAQ  Forum Search   Register Register  Login Login

User Data - Get Button Name When Pressed

 Post Reply Post Reply
Author
Message
DurangoSauce View Drop Down
Member
Member


Joined: 2018 May 11
Online Status: Offline
Posts: 2
Post Options Post Options   Quote DurangoSauce Quote  Post ReplyReply Direct Link To This Post Topic: User Data - Get Button Name When Pressed
    Posted: 2018 May 11 at 10:15pm
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?


Back to Top
Andreas Block View Drop Down
Forum Moderator
Forum Moderator
Avatar

Joined: 2014 Oct 01
Location: Hannover
Online Status: Offline
Posts: 1847
Post Options Post Options   Quote Andreas Block Quote  Post ReplyReply Direct Link To This Post Posted: 2018 May 14 at 7:01am
Hi,

welcome to the Plugin Café forums Smile

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"

Cheers,
Andreas
SDK Support Engineer
Back to Top
DurangoSauce View Drop Down
Member
Member


Joined: 2018 May 11
Online Status: Offline
Posts: 2
Post Options Post Options   Quote DurangoSauce Quote  Post ReplyReply Direct Link To This Post Posted: 2018 May 14 at 10:33pm
Hi Andreas,

Thanks! That worked perfectly. Smile

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

Thanks,
Mike
Back to Top
 Post Reply Post Reply

Forum Jump Forum Permissions View Drop Down

Bulletin Board Software by Web Wiz Forums® version 9.61 [Free Express Edition]
Copyright ©2001-2009 Web Wiz

This page was generated in 0.094 seconds.