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

    add Userdata with details

    Scheduled Pinned Locked Moved PYTHON Development
    17 Posts 0 Posters 1.4k 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 25/04/2013 at 09:35, xxxxxxxx wrote:

      you are right nikklas, it is just a habit of precaution i got used to before trying to 
      invoke any methods. i generally am too lazy or bad to check if my code is efficient. 
      more a python user here rather than a real programmer 😉

      my second posting sounds a bit grumpy when i am reading it now again, which was
      actually not intentional.

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

        On 26/04/2013 at 02:31, xxxxxxxx wrote:

        Niklas and Ferdinand,

        thanks for the detailed replies, 
        Im a bit confused - the Id i get back is a Integer - but with that i dont get any data or value

        for id_, bc in op.GetUserDataContainer() :
            print "id:"
            rig = id_[id_.GetDepth() - 1].id
            print bc.GetCustomDataType(rig)

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

          On 26/04/2013 at 02:32, xxxxxxxx wrote:

          Hi connor,

          Probably because the attribute is not a custom data type..? Have you tried using __getitem__() ?

              print bc[rig]
          
          1 Reply Last reply Reply Quote 0
          • H Offline
            Helper
            last edited by

            On 26/04/2013 at 04:16, xxxxxxxx wrote:

            i try :

            for id_, bc in op.GetUserDataContainer() :
               	rig = id_[id_.GetDepth() - 1].id
                	#print bc.GetCustomDataType(rig)
                	print bc.__getitem__(rig)
                	print bc[rig]
            	print "name:"
                	print bc[c4d.DESC_NAME] 
                	print "unit:"
                	print bc[c4d.DESC_UNIT] 
            

            ig get for both None

            Name and Unit are correct

            i try to grap user data to and merge it to a gui interface

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

              On 26/04/2013 at 04:32, xxxxxxxx wrote:

              Lol, sorry I messed up that bc is the item description container, not the host's container.
              So, what are you actually trying to do? Do you want to obtainthe parameter-name, min/max, etc. or
              do you want to get the actual parameters value?

              for id_, bc in op.GetUserDataContainer() :
                  print bc[c4d.DESC_NAME]
                  print op[id_] # Same as     op[c4d.ID_USERDATA, id_[id_.GetDepth() - 1]]
              
              1 Reply Last reply Reply Quote 0
              • H Offline
                Helper
                last edited by

                On 26/04/2013 at 07:37, xxxxxxxx wrote:

                hey niklas,

                both of them i need actual values and mast of the descriptions like max or min to rebuild the interface in a gui

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

                  On 26/04/2013 at 08:37, xxxxxxxx wrote:

                  you are aware that there are no dynamic descriptions in python and rebuilding a userdata
                  description container with a dialog resource can also become quite tricky, as dialog resources
                  and descriptions are not the same, although both are resource based.

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

                    On 26/04/2013 at 09:28, xxxxxxxx wrote:

                    First the solution to your request.
                    Here is some code that will change the Min attribute on a Real type UD entry:

                    import c4d  
                    def main() :  
                        
                      obj = doc.GetFirstObject()      #The object hosting the UD    
                      ud = obj.GetUserDataContainer() #The master UD container  
                        
                      for i, bc in ud:  
                          level = i[1].id             #Get the ID# for each UD entry  
                            
                          if level == 1:              #If we find the first UD entry  
                              bc[5]=  0.2             #Set the Min value to 20% in memory only!!!  
                              obj.SetUserDataContainer(i, bc) #Set the container changes from memory  
                        
                      c4d.EventAdd()  
                         
                    if __name__=='__main__':  
                      main()
                    

                    How did I come up with this code?
                    I had to learn about how the UD system works. It's a rather convoluted system of a master base container. With sub containers. Which hold values consisting of Reals, Longs, Vectors, and Tuples.
                    Then I mapped it out and made a note for myself to use as a reference guide on how to get at a specific UD attribute.

                    This is one of several notes I've written to myself about How the UD system works.
                    And how to get at the specific built-in attributes inside of them:

                    #This is how to get at the options in a specific UD entry  
                    #The options are different depending on what kind of UD item it is  
                    #These options are descriptions found under "cid DESC_Items" in the sdk (lib_description.h)  
                      
                    import c4d  
                    def main() :  
                        
                      obj = doc.GetFirstObject()      #The object hosting the UD    
                      ud = obj.GetUserDataContainer() #The master UD container  
                        
                      first = ud[0]                   #The first UD entry (by it's stack position...not it's ID#)  
                      
                      #first is now a variable that holds a tuple of two base containers  
                      #first[0] holds the level ID#, and two DescLevel objects  
                      #first[1] holds the various options for the UD entry. Changed by accessing their descriptions  
                      
                      #Here is an example of accessing those options:  
                      
                      container = first[1]            #The second tuple container of the UD entry. Which holds most of the attributes  
                        
                      for i in container:  
                          print i                     #Prints the container ID#s, values  
                      
                      
                      #Examples of what some of these options are for the default UD type entry:  
                      
                      level    = first[0][1].id          #The level ID#  
                      Lname    = first[1][1]             #The long name  
                      Sname    = first[1][2]             #The short name  
                      three    = first[1][3]             # 3 for certain UD types  
                      minValue = first[1][5]             #Min value  
                      maxValue = first[1][6]             #Max value   
                      step     = first[1][9]             #Step Value  
                      anim     = first[1][10]            #Animatable option  
                      meters   = first[1][12]            #units type  
                      tupleData =first[1][13]            # (700, 5, 0)  
                      interface =first[1][21]            #interface type (float=19,  
                                                                      #float slider=1000489,  
                                                                      #float slider noedit = 200000006,  
                                                                      #lat/lon = 1011148)  
                      
                      minslider =first[1][27]            #The min slider value (if enabled)  
                      
                    if __name__=='__main__':  
                      main()
                    

                    I hope that help demystify UD a little bit.
                    IMHO. The UD system is rather convoluted. Which I why I wrote myself lots of helper notes & guides like this one about it.

                    -ScottA

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

                      On 07/06/2013 at 16:23, xxxxxxxx wrote:

                      hey thanks for the many replies - i try to use DESC_PARENTGROUP to create own groups in the userdata - without success - has one of you a idea or an example how create own userdata groups

                      Many Thanks

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

                        On 07/06/2013 at 17:12, xxxxxxxx wrote:

                        Yeah. I have an example of using UD groups.

                        This script creates a python tag on the selected object. And then adds a UD group to it. Then it adds a couple of things into that group.

                        import c4d  
                        def main() :  
                          
                          obj = doc.GetActiveObject()      
                          pyTag = c4d.BaseTag(1022749)      #Create a python tag to host the User Data  
                            
                          #The top most parent group  
                          rootGroup = c4d.GetCustomDatatypeDefault(c4d.DTYPE_GROUP)  
                          rootGroup[c4d.DESC_NAME] = "Root"  
                          rootGroup[c4d.DESC_TITLEBAR] = False  
                          rootGroup[c4d.DESC_LAYOUTGROUP] = True  
                          rootGroup[c4d.DESC_COLUMNS] = 3  
                          pyTag.AddUserData(rootGroup)  
                          
                          #A group that's a child of the root group  
                          childGroup = c4d.GetCustomDatatypeDefault(c4d.DTYPE_GROUP)  
                          childGroup[c4d.DESC_NAME] = "childGroup"  
                          childGroup[c4d.DESC_TITLEBAR] = False  
                          childGroup[c4d.DESC_PARENTGROUP] = pyTag.GetUserDataContainer()[0][0]  
                          pyTag.AddUserData(childGroup)  
                          
                           
                          #A string type UD entry for this group  
                          childGrp_Item1 = c4d.GetCustomDatatypeDefault(c4d.DTYPE_STRING)  
                          childGrp_Item1[c4d.DESC_NAME] = "Item1"  
                          childGrp_Item1[c4d.DESC_PARENTGROUP] = pyTag.GetUserDataContainer()[1][0]  
                          pyTag[pyTag.AddUserData(childGrp_Item1)] ="Hello World"  
                          
                          
                          #A Real type UD entry for this group  
                          childGrp_Item2 = c4d.GetCustomDatatypeDefault(c4d.DTYPE_REAL)  
                          childGrp_Item2[c4d.DESC_NAME] = "Item2"  
                          childGrp_Item2[c4d.DESC_PARENTGROUP] = pyTag.GetUserDataContainer()[1][0]  
                          pyTag[pyTag.AddUserData(childGrp_Item2)] = 55.6   
                            
                          obj.InsertTag(pyTag)  
                          c4d.EventAdd()  
                          
                        if __name__=='__main__':  
                          main()
                        

                        -ScottA

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

                          On 13/06/2013 at 07:46, xxxxxxxx wrote:

                          thanks scottA , is it possible to get out of the default user data group to create tab-items

                          Thanks

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

                            On 13/06/2013 at 10:02, xxxxxxxx wrote:

                            You lost me on that one.
                            UserData is created inside the UserData tab.

                            If you're you asking me if we can create more than one User Data tab. And name them with our own custom names. My answer is I don't know. I've never tried it.
                            But that's a good question.

                            -ScottA

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