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

    Detect a User Data button

    Scheduled Pinned Locked Moved PYTHON Development
    8 Posts 0 Posters 785 Views
    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 Offline
      Helper
      last edited by

      On 20/05/2016 at 09:09, xxxxxxxx wrote:

      Cinema 4D R17 has a User Data type of Button.
      How can a script detect that a User Data button was clicked?

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

        On 20/05/2016 at 11:15, xxxxxxxx wrote:

        This was posted in forum somewhere.
        But I'll save you the trouble of looking for it. 😉

        #This is how to capture the button click event on the new button UserData gizmo in R16  
        #The code goes in a python tag  
        #Assumes that the UD button is at index #1 and the UD button is on the object...not the 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 == 1:  
                      print "UD Button Pressed"  
          
        def main() :  
            
          obj = op.GetObject()  
          bc = c4d.BaseContainer()  
          obj.AddEventNotification(op, c4d.NOTIFY_EVENT_MESSAGE, 0, bc)
        

        -ScottA

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

          On 20/05/2016 at 11:24, xxxxxxxx wrote:

          Great!!! Thank you, Scott

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

            On 23/05/2016 at 01:39, xxxxxxxx wrote:

            Hi Rui,

            Event notifications aren't recommended but that's the current solution.

            However, note that the upcoming Service Update for R17 fixes this issue catching user data buttons pressed in Python tags.
            The MSG_DESCRIPTION_COMMAND will be sent without the need for registering an event notification.

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

              On 23/05/2016 at 03:07, xxxxxxxx wrote:

              Great to know that.
              I'm considering the idea of writing a book on python (just like I did, on COFFEE) and all this information is very valuable.

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

                On 05/07/2016 at 02:50, xxxxxxxx wrote:

                Thank you, Scott, for a nice code snippet, but i have no idea how to use it in XPresso. Can you show a little example?

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

                  On 05/07/2016 at 08:34, xxxxxxxx wrote:

                  I don't know that either Mike.
                  Maybe the support guys have an answer?

                  -ScottA

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

                    On 06/07/2016 at 02:05, xxxxxxxx wrote:

                    Hi Mike,

                    The Python XPresso node doesn't support the message() function.
                    And it's not a good idea to catch a button pressed inside a Python node. An XPresso node should only calculate output(s) with its input(s).

                    What operation(s) would be performed when the button is pressed?

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