ID Userdata Q



  • THE POST BELOW IS MORE THAN 5 YEARS OLD. RELATED SUPPORT INFORMATION MIGHT BE OUTDATED OR DEPRECATED

    On 15/01/2012 at 08:09, xxxxxxxx wrote:

    Started looking at adding and removing user data

    I can see how to add
    and remove

    now if I have this correct
    the remove relies on the number ID

    obj.RemoveUserData([c4d.ID_USERDATA, 1])
    

    But if a user has already added user data 
    the number will not always start at one

    2 Qs:

    1 how do you get that number
    2  how do you track the user data items that you add?

    I've tried getting the number ID_USERDATA but with no luck

    I can only get what I think is referred to as a tuple
    (1,15,0)
    and guessing this is reflects the user data  (numerical index, type, ???)

    thoughts appreciated

    Paul

    add a cube 
    add user data
    select cube
    run script

      
    import c4d
    from c4d import gui
    #Welcome to the world of Python
      
      
      
    def main() :
        c4d.CallCommand(13957); # Clear console
        doc = c4d.documents.GetActiveDocument()
        sel_obj = doc.GetActiveObject()
        id_with_bc = sel_obj.GetUserDataContainer()
      
        for id, bc in sel_obj.GetUserDataContainer() :
            print id, bc, bc[c4d.DESC_NAME], bc[c4d.ID_USERDATA]  
      
      
        print " "
        print "is this the id", id_with_bc[0][0]
      
      
    if __name__=='__main__':
        main()
    


  • THE POST BELOW IS MORE THAN 5 YEARS OLD. RELATED SUPPORT INFORMATION MIGHT BE OUTDATED OR DEPRECATED

    On 20/01/2012 at 02:51, xxxxxxxx wrote:

    Hi Paul,

    When we call AddUserData(), it returns a DescID (the tuple you are refering to) containing the identification data we can then send to RemoveUserData().
    If the user data has not been added by our code, we can get the DescID by looping trough the user data container with GetUserDataContainer().

    Here is an example showing how to deal with user data DescID, DesLevel, type etc.:

    import c4d
      
      
    def AddLongDataType(obj) :
        if obj is None: return
      
        bc = c4d.GetCustomDatatypeDefault(c4d.DTYPE_LONG) # Create default container
        bc[c4d.DESC_NAME] = "Test"                        # Rename the entry
      
        element = obj.AddUserData(bc)     # Add userdata container
        
        for i in range(0, element.GetDepth()) :
            print element[i].id                  # element[i] is a DescLevel object
            print element[i].dtype
        
        # element[0] is for c4d.ID_USERDATA
        # element[1] is for our user data
        
        print "Added user data : ", element[1].id
        
        obj[element] = 30                 # Assign a value
        c4d.EventAdd()                    # Update
      
    def RemoveLongDataType(obj) :
        for element, bc in obj.GetUserDataContainer() :
            if element[1].dtype == c4d.DTYPE_LONG:
                if obj.RemoveUserData(element) :
                    print "Removed user data : ", element[1].id
                
                # To remove the data we could also call:
                # obj.RemoveUserData(element[1].id)
                # obj.RemoveUserData([c4d.ID_USERDATA, element[1].id])
        c4d.EventAdd()                    # Update
      
      
    def main() :
        AddLongDataType(op)
        RemoveLongDataType(op)
      
    if __name__=='__main__':
        main()
    

    Yannick


Log in to reply