Listening for Checkbox Clicks in User Data



  • On 22/08/2018 at 14:13, xxxxxxxx wrote:

    Hello,
    Is it possible, with a Python tag or otherwise, to listen for the click of an object's User Data checkbox? I have gotten this to work with the User Data button in the past. I'm looking to run some scripts when the user checks a "Use IK" checkbox.

    I tried overriding the "message" method in my Python tag, but I couldn't find any of the attributes for the data object that gets passed as a parameter. In my web searches, it seemed that attributes such as 'descid' only existed for certain types of message data.

    Any clarification on how to set this up (and decipher the message data) would be very helpful. Thank you.



  • On 23/08/2018 at 02:03, xxxxxxxx wrote:

    Hi BlastFrame !

    Actually there is a way, but is not recommended and pretty experimental, so if strange behavior occurs, we can't do anything. In the same time it's the only solution.
    Whith that said we get AddEventNotification, which allow to receive message from another object.
    Here is the code of the python tag

    import c4d
      
    def message(msg_type, data) :
        if msg_type == c4d.MSG_NOTIFY_EVENT:
            event_data = data['event_data']
            if event_data['msg_id'] == c4d.MSG_DESCRIPTION_POSTSETPARAMETER:
                desc_id = event_data['msg_data']['descid']
                if desc_id[1].id == 1:
                    print op.GetObject()[c4d.ID_USERDATA,1]
      
    def main() :
        obj = op.GetObject()
        
        # Check if we already listen for message
        if not obj.FindEventNotification(doc, op, c4d.NOTIFY_EVENT_MESSAGE) :
            obj.AddEventNotification(op, c4d.NOTIFY_EVENT_MESSAGE, 0, c4d.BaseContainer())
    

    If you have any questions, pelase let me know.
    Cheers,
    Maxime.



  • On 24/08/2018 at 15:02, xxxxxxxx wrote:

    This works! Thank you, Maxime.

    It may be worth calling out that this line's id  attribute is the ID assigned when creating the User Data:
    if desc_id[1].id == 1:

    It took me a little to figure this out.

    Thank you, again!