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
    • Recent
    • Tags
    • Users
    • Login

    access userdata inside userdata group [SOLVED]

    Scheduled Pinned Locked Moved PYTHON Development
    16 Posts 0 Posters 1.3k 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 09/07/2015 at 06:00, xxxxxxxx wrote:

      Originally posted by xxxxxxxx

      I get an error message:

      Traceback (most recent call last) :
      File "scriptmanager", line 11 in ,module.
      TypeError:_setitem_expected int or bool, not None

      Hi
      I test code and simple print to dive in to level

          for id, bc in op.GetUserDataContainer() :  
            print bc[c4d.DESC_PARENTGROUP][-1].id  
            if bc[c4d.DESC_PARENTGROUP][-1].id == 700:  
                op[id] = bc[c4d.DESC_DEFAULT]
      

      i have id in level = 700.

      Try such, code works for me

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

        On 09/07/2015 at 06:18, xxxxxxxx wrote:

        I tried your code and still get the same error message.

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

          On 09/07/2015 at 06:22, xxxxxxxx wrote:

          If I try this code from the Script Manager, it works and only userdata from group 255 is reset but when it is on a Python tag, it doesn't. Any suggestions?

          import c4d

          for id, bc in op.GetUserDataContainer() :
              
              if bc[c4d.DESC_PARENTGROUP][-1].id == 255:
                  try:
                      op[id] = bc[c4d.DESC_DEFAULT]
                  except TypeError:
                       #No or invalid default value.
                      pass

          c4d.EventAdd()

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

            On 09/07/2015 at 08:02, xxxxxxxx wrote:

            For a Python Tag, "op" is the Tag, not the Object. Use the variable "obj" in all places instead of "op" and add "obj = op.GetObject()" beforehand.

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

              On 09/07/2015 at 10:57, xxxxxxxx wrote:

              Thanks, Niklas, that totally worked! The last thing I need and can't get to work is the switch. Here is what I have:

              import c4d

              obj = op.GetObject()
              ID_RESET_Iceland = 39
                      
              def main() :
                  
                  for id, bc in obj.GetUserDataContainer() :
                      
                      if bc[c4d.DESC_PARENTGROUP][-1].id == 255:
                          
                          if obj[c4d.ID_USERDATA, ID_RESET_Iceland]:
                              obj[c4d.ID_USERDATA, ID_RESET_Iceland] = False
                              
                              try:
                                  obj[id] = bc[c4d.DESC_DEFAULT]
                              except TypeError:
                                   #No or invalid default value.
                                  pass
                  
                  c4d.EventAdd()

              if __name__=='__main__':
                  main()

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

                On 09/07/2015 at 11:44, xxxxxxxx wrote:

                I now have this but it still doesn't work.

                import c4d

                obj = op.GetObject()
                ID_RESET_Iceland = 39
                        
                def main() :
                    
                    for id, bc in obj.GetUserDataContainer() :
                        
                        if (bc[c4d.DESC_PARENTGROUP][-1].id == 255 and 
                        obj[c4d.ID_USERDATA, ID_RESET_Iceland] == False) :
                           
                                try:
                                    obj[id] = bc[c4d.DESC_DEFAULT]
                                except TypeError:
                                     #No or invalid default value.
                                    pass
                    
                    c4d.EventAdd()

                if __name__=='__main__':
                    main()

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

                  On 09/07/2015 at 17:10, xxxxxxxx wrote:

                  Try this instead

                  import c4d
                  ID_RESET_Iceland = 39
                          
                  def main() :
                      obj = op.GetObject()
                      if not obj[c4d.ID_USERDATA, ID_RESET_Iceland]:
                          return
                      obj[c4d.ID_USERDATA, ID_RESET_Iceland] = False
                    
                      for id, bc in obj.GetUserDataContainer() :    
                          if bc[c4d.DESC_PARENTGROUP][-1].id == 255:
                              try:
                                  obj[id] = bc[c4d.DESC_DEFAULT]
                              except TypeError:
                                  pass
                      c4d.EventAdd()
                  

                  Don't use that __name__ == "__main__" part in a Python Tag

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

                    On 09/07/2015 at 19:59, xxxxxxxx wrote:

                    It works! You are a genius! Thanks very much for this Niklas. 🙂

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

                      On 09/07/2015 at 20:19, xxxxxxxx wrote:

                      One problem, the script keeps looping after I activate the reset button. Is there a way to stop it?

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

                        On 09/07/2015 at 20:23, xxxxxxxx wrote:

                        Figured that out. Moved c4d.EventAdd() out of the for loop. But now it resets regardless of whether or not the reset switch is activated.

                        import c4d
                        ID_RESET_Iceland = 39
                                
                        def main() :
                            obj = op.GetObject()
                            if not obj[c4d.ID_USERDATA, ID_RESET_Iceland]:
                                return
                            obj[c4d.ID_USERDATA, ID_RESET_Iceland] = False

                        for id, bc in obj.GetUserDataContainer() :    
                                if bc[c4d.DESC_PARENTGROUP][-1].id == 255:
                                    try:
                                        obj[id] = bc[c4d.DESC_DEFAULT]
                                    except TypeError:
                                        pass
                           
                                        
                        c4d.EventAdd()

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

                          On 10/07/2015 at 15:48, xxxxxxxx wrote:

                          Got it working! I had the wrong userdata id number.

                          import c4d

                          def main() :
                              
                              ID_RESET_Iceland = 121
                              obj = doc.SearchObject("DEEP FREEZE")
                              #obj = op.GetObject()
                              
                              if obj[c4d.ID_USERDATA, ID_RESET_Iceland]:
                                  obj[c4d.ID_USERDATA, ID_RESET_Iceland] = False

                          for id, bc in obj.GetUserDataContainer() :    
                                      if bc[c4d.DESC_PARENTGROUP][-1].id == 255:
                                          try:
                                              obj[id] = bc[c4d.DESC_DEFAULT]
                                          except TypeError:
                                              pass
                                              
                                  for id, bc in obj.GetUserDataContainer() :    
                                      if bc[c4d.DESC_PARENTGROUP][-1].id == 277:
                                          try:
                                              obj[id] = bc[c4d.DESC_DEFAULT]
                                          except TypeError:
                                              pass
                                              
                                  for id, bc in obj.GetUserDataContainer() :    
                                      if bc[c4d.DESC_PARENTGROUP][-1].id == 515:
                                          try:
                                              obj[id] = bc[c4d.DESC_DEFAULT]
                                          except TypeError:
                                              pass
                                              
                                  for id, bc in obj.GetUserDataContainer() :    
                                      if bc[c4d.DESC_PARENTGROUP][-1].id == 516:
                                          try:
                                              obj[id] = bc[c4d.DESC_DEFAULT]
                                          except TypeError:
                                              pass
                              
                             
                                          
                          c4d.EventAdd()

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