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

    User Data button Python Tag r19 - avoid "index out of depth" console feedback

    Cinema 4D SDK
    r19 python
    2
    4
    872
    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.
    • Leo_SaramagoL
      Leo_Saramago
      last edited by Leo_Saramago

      Hello, there!

      The following code works(Python Tag). Whenever I press the User Data button, the global position coordinates from the object(cube) get stored in three separate User Data fields. Great!

      The issue rises whenever the input in those three fields gets done manually, via keyboard, which is something totally valid for my purposes. Console says "index out of depth", and I just can't figure out how to avoid going that deep with the "if" comparisons, I mean, my goal is to stop passing the "if" tests whenever the messages come from inputs other than the User Data button.

      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 != None: #Trying to avoid 'Index Out of Depth' console messages
      
                      if desc_id[1].dtype == c4d.DTYPE_BUTTON:
                          #Gets Driver Object Global Matrix and stores its Global Position
                          o = doc.SearchObject("Drv")
                          if o:
                              m = o.GetMg()
                              pos = m.off
                  
                          #Update Button Hit
                          if desc_id[1].id == 1:
                      
                              op[c4d.ID_USERDATA,1][c4d.ID_USERDATA,2] = pos[0]
                              op[c4d.ID_USERDATA,1][c4d.ID_USERDATA,4] = pos[1]
                              op[c4d.ID_USERDATA,1][c4d.ID_USERDATA,3] = pos[2]
                                  
                              c4d.EventAdd()
                  
                          else:
                              return
      
      
      def main():
          pass
      
      

      Thanks for your Attention,

      Leo

      "The idea dictates everything."

      by David Lynch

      1 Reply Last reply Reply Quote 0
      • Leo_SaramagoL
        Leo_Saramago
        last edited by

        User Data Button test.c4d

        This is the test .c4d file.

        Once again, thanks for your time.

        "The idea dictates everything."

        by David Lynch

        1 Reply Last reply Reply Quote 0
        • ManuelM
          Manuel
          last edited by Manuel

          hello,

          The error message make sense as you are trying to reach a level on the DescID that doesn't exist.

          So to avoid that you can simply check the depth of the DescID using GetDepth() to check if it's superior to 1.

          or

          you can create a DescID that you know your button will have and simply compare equalisty

          import c4d
          
          
          myButtonID = 1
          myByttonDescID = c4d.DescID(c4d.DescLevel(c4d.ID_USERDATA , c4d.DTYPE_SUBCONTAINER ,0), c4d.DescLevel(myButtonID, c4d.DTYPE_BUTTON,0))
          
          
          
          def message(id, data):
          
              if id == 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']
                      #first solution check if the descid depth is more than one
                      #if desc_id.GetDepth() > 1:
                      
                      #second solution, we compare the id with the descID we know our button will have.
                      if desc_id == myByttonDescID:
                          #Gets Driver Object Global Matrix and stores its Global Position
                          o = doc.SearchObject("Drv")
                          if o:
                              m = o.GetMg()
                              pos = m.off
          
                          #Update Button Hit
                          if desc_id[1].id == 1:
          
                              op[c4d.ID_USERDATA,1][c4d.ID_USERDATA,2] = pos[0]
                              op[c4d.ID_USERDATA,1][c4d.ID_USERDATA,4] = pos[1]
                              op[c4d.ID_USERDATA,1][c4d.ID_USERDATA,3] = pos[2]
          
                              c4d.EventAdd()
          
                          else:
                              return
          
          
          def main():
              pass
          

          and this will allow you to have several button.

          Cheers
          Manuel

          MAXON SDK Specialist

          MAXON Registered Developer

          1 Reply Last reply Reply Quote 2
          • Leo_SaramagoL
            Leo_Saramago
            last edited by

            @m_magalhaes said in User Data button Python Tag r19 - avoid "index out of depth" console feedback:

            if desc_id.GetDepth() > 1

            Thanks a lot, Manuel! It's perfect now.

            "The idea dictates everything."

            by David Lynch

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