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

    Get userdata Button state on object in Python tag

    Cinema 4D SDK
    python r20
    2
    7
    2.5k
    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.
    • B
      bonsak
      last edited by

      Hi
      I have a userdata button on a null and a python tag on that null. In the tag i try to get the state of the button on the object:

      import c4d
      #Welcome to the world of Python
      
      def message(id, data) :
        if id == 17:
            print "UserData-ID: ", data["descid"][1].id
      

      This only works if the userdata button is on the tag. How can i get the state of the userdata botton on the object from inside the python tag?

      Regards
      Bonsak

      1 Reply Last reply Reply Quote 0
      • M
        m_adam
        last edited by

        Hi @bonsak, there is a way but is not recommended and pretty experimental, so if a strange behavior occurs, we can't do anything. In the same time, it's the only solution.

        With that said we get AddEventNotification, which allow receiving messages 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_COMMAND:
                    desc_id = event_data['msg_data']['id']
                    if desc_id[1].id == 17: # The ID of the User Data
                        print "Button Pressed"
        
        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())
        

        Cheers,
        Maxime.

        MAXON SDK Specialist

        Development Blog, MAXON Registered Developer

        1 Reply Last reply Reply Quote 2
        • B
          bonsak
          last edited by m_adam

          Thanks!
          I couldnt get it to work without modifying it like this:

          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_COMMAND:
                      #print event_data['msg_id']
                      if event_data['msg_data']['id'][1].id == 18:
                          print "Button Pressed"
                      #desc_id = event_data['msg_data']['id']
                      #if desc_id[1].id == 17: # The ID of the User Data
                      #    print "Button Pressed"
          
          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())
          

          Regards
          Bonsak
          EDIT m_adam: Fixed your code snippet

          1 Reply Last reply Reply Quote 0
          • M
            m_adam
            last edited by

            Which version do you use?
            Can you provide a scene?

            MAXON SDK Specialist

            Development Blog, MAXON Registered Developer

            1 Reply Last reply Reply Quote 0
            • B
              bonsak
              last edited by

              R20 20.0.30
              0_1542379593819_userdata-button.c4d

              1 Reply Last reply Reply Quote 0
              • M
                m_adam
                last edited by m_adam

                Hi @bonsak,

                The code within the file and in the forum is not the same.
                The actual issue in your code posted on the forum is you are checking for if event_data['msg_id'] == 18: instead of if event_data['msg_data']['id'][1].id == 18:

                Moreover, in the scene you attached which use my code, the button ID is set to 2.
                So if you change if event_data['msg_id'] == 18: toif event_data['msg_id'] == 2: make it works.

                Cheers,
                Maxime.

                MAXON SDK Specialist

                Development Blog, MAXON Registered Developer

                1 Reply Last reply Reply Quote 0
                • B
                  bonsak
                  last edited by bonsak

                  Ah! So event_data['msg_data']['id'] is the id of the userdata.
                  Didnt read your code comments 🙂
                  Thanks alot!

                  Regards
                  Bonsak

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