place Group description outside of userdata tab



  • On 25/10/2016 at 14:48, xxxxxxxx wrote:

    I'm writing a script to create a bunch of userdata for some rig controllers.
    I figured out how to set custom id's and organize the descriptions into groups, but there's still one thing I couldn't figure out.

    Is there a way to place a group description into its own AM tab by scripting? I've been searching through the documentation but I couldn't find the id to parent the group to. It's always dropped in the 'UserData' group.

    here's my code so far:

    import c4d  
      
    dct = {  
      "space"   : 1000,  
        
      "root"    : 1001,  
      "cog"     : 1002,  
      "chest"   : 1003,  
        
      "collar"  : 2001,  
      "shoulder": 2002,  
      "elbow"   : 2003,  
      "wrist"   : 2004,  
      
      "hip"     : 3002,  
      "knee"    : 3003,  
      "ankle"   : 3004,  
      "ball"    : 3005,  
    }  
      
    def AddGroup( name, obj, gid ) :  
      bc = c4d.GetCustomDataTypeDefault( c4d.DTYPE_GROUP )  
        
      bc[ c4d.DESC_PARENTGROUP ] = gid  
      bc[ c4d.DESC_NAME        ] = name  
      bc[ c4d.DESC_TITLEBAR    ] = True  
      
      bc[ c4d.DESC_PARENTID    ] = None  
      
      
      did = c4d.DescID(c4d.DescLevel(c4d.ID_USERDATA), c4d.DescLevel( dct[ name ] )) #<- i don't know which DescLevel value to use  
      
      obj.SetUserDataContainer( did, bc )  
      
      return  
      
      b = obj.GetUserDataContainer()  
        
      if b is None:  
          return  
      else:  
          dummyid = obj.AddUserData( bc )  
          b = obj.GetUserDataContainer()  
      
          b[0][0].SetId( c4d.DescLevel( uid ) )  
          obj.SetUserDataContainer( b[0][0], bc )  
          obj.RemoveUserData( dummyid )  
      
      return 1000  
      
    def AddSlider( name, obj, gid ) :  
        
      bc = c4d.GetCustomDataTypeDefault( c4d.DTYPE_REAL )  
        
      bc[c4d.DESC_PARENTGROUP] = gid  
      bc[c4d.DESC_NAME       ] = name  
      bc[c4d.DESC_SHORT_NAME ] = name  
      
      bc[c4d.DESC_MIN        ] = 0.0  
      bc[c4d.DESC_MAX        ] = 1.0  
      bc[c4d.DESC_STEP       ] = 0.01  
      bc[c4d.DESC_UNIT       ] = c4d.DESC_UNIT_PERCENT  
      bc[c4d.DESC_CUSTOMGUI  ] = c4d.CUSTOMGUI_REALSLIDER  
      
      did = c4d.DescID( c4d.DescLevel( c4d.ID_USERDATA ), c4d.DescLevel( dct[ name ] ) )  
      
      obj.SetUserDataContainer( did, bc )  
      
      return  
            
    def main() :  
      obj = doc.GetActiveObject()  
      #obj = doc.GetActiveTag()  
      
      doc.StartUndo()  
      doc.AddUndo( c4d.UNDOTYPE_CHANGE_SMALL, obj )          
      
      for descid, bc in obj.GetUserDataContainer() :  
          print descid, bc[ c4d.DESC_PARENTGROUP ]  
        
      AddGroup ( "space",   obj, 100 )  
        
      gid = c4d.DescID(c4d.DescLevel(c4d.ID_USERDATA), c4d.DescLevel( dct[ "space" ] )) #using 'space' group as parent for next elements  
        
      AddSlider( "root",     obj, gid )  
      AddSlider( "cog",      obj, gid )  
      AddSlider( "chest",    obj, gid )  
        
      AddSlider( "collar",   obj, gid )  
      AddSlider( "shoulder", obj, gid )  
      AddSlider( "elbow",    obj, gid )  
      AddSlider( "wrist",    obj, gid )  
      
      #AddSlider( "collar",  3001, obj )  
      AddSlider( "hip",      obj, gid )  
      AddSlider( "knee",     obj, gid )  
      AddSlider( "ankle",    obj, gid )  
      AddSlider( "ball",     obj, gid )  
      
      doc.EndUndo()  
      c4d.EventAdd()  
            
      return  
    if __name__=='__main__':  
      main()
    


  • On 25/10/2016 at 17:19, xxxxxxxx wrote:

    Try this version of your script.
    It should create the sliders in a "My Sliders" tab instead of the standard "UserData" tab

    import c4d  
      
    dct = {  
      "space"   : 1000,  
        
      "root"    : 1001,  
      "cog"     : 1002,  
      "chest"   : 1003,  
        
      "collar"  : 2001,  
      "shoulder": 2002,  
      "elbow"   : 2003,  
      "wrist"   : 2004,  
      
      "hip"     : 3002,  
      "knee"    : 3003,  
      "ankle"   : 3004,  
      "ball"    : 3005,  
    }  
      
    def AddGroup( name, obj, gid ) :  
      bc = c4d.GetCustomDataTypeDefault( c4d.DTYPE_GROUP )  
        
      bc[ c4d.DESC_PARENTGROUP ] = gid  
      bc[ c4d.DESC_NAME        ] = name  
      bc[ c4d.DESC_TITLEBAR    ] = True  
      
      bc[ c4d.DESC_PARENTID    ] = None  
      
      did = c4d.DescID(c4d.DescLevel(c4d.ID_USERDATA), c4d.DescLevel( dct[ name ] )) #<- i don't know which DescLevel value to use  
      
      obj.SetUserDataContainer( did, bc )  
      
      return  
      
      b = obj.GetUserDataContainer()  
        
      if b is None:  
          return  
      else:  
          dummyid = obj.AddUserData( bc )  
          b = obj.GetUserDataContainer()  
      
          b[0][0].SetId( c4d.DescLevel( uid ) )  
          obj.SetUserDataContainer( b[0][0], bc )  
          obj.RemoveUserData( dummyid )  
      
      return 1000  
      
    def AddSlider( name, obj, gid ) :  
        
      bc = c4d.GetCustomDataTypeDefault( c4d.DTYPE_REAL )  
        
      bc[c4d.DESC_PARENTGROUP] = gid  
      bc[c4d.DESC_NAME       ] = name  
      bc[c4d.DESC_SHORT_NAME ] = name  
      
      bc[c4d.DESC_MIN        ] = 0.0  
      bc[c4d.DESC_MAX        ] = 1.0  
      bc[c4d.DESC_STEP       ] = 0.01  
      bc[c4d.DESC_UNIT       ] = c4d.DESC_UNIT_PERCENT  
      bc[c4d.DESC_CUSTOMGUI  ] = c4d.CUSTOMGUI_REALSLIDER  
      
      did = c4d.DescID( c4d.DescLevel( c4d.ID_USERDATA ), c4d.DescLevel( dct[ name ] ) )  
      
      obj.SetUserDataContainer( did, bc )  
      
      return  
            
    def main() :  
      
      obj = doc.GetActiveObject()  
      if not obj: return False  
        
      doc.StartUndo()  
      doc.AddUndo( c4d.UNDOTYPE_CHANGE_SMALL, obj )      
        
      #The topmost group will be the AM TAB itself  
      Groupbc = c4d.GetCustomDatatypeDefault(c4d.DTYPE_GROUP)  
      Groupbc[c4d.DESC_PARENTGROUP] = c4d.DescID(0)  #<---Points to the tab's ID  
      Groupbc[c4d.DESC_NAME] = "My Sliders"          #<---The text dipayed in the TAB instead of UserData  
      Groupbc[c4d.DESC_TITLEBAR] = True  
      obj.AddUserData(Groupbc)          
      
      #for descid, bc in obj.GetUserDataContainer() :  
      #    print descid, bc[ c4d.DESC_PARENTGROUP ]  
        
      AddGroup ( "space",   obj, 100 )  
        
      #Adds the sliders to the new group in the "UserData" tab  
      #gid = c4d.DescID(c4d.DescLevel(c4d.ID_USERDATA), c4d.DescLevel( dct[ "space" ] ))  
      
      #Adds the sliders to the new group in the "My Sliders" tab  
      gid = obj.GetUserDataContainer()[0][0]  
        
      AddSlider( "root",     obj, gid )  
      AddSlider( "cog",      obj, gid )  
      AddSlider( "chest",    obj, gid )  
        
      AddSlider( "collar",   obj, gid )  
      AddSlider( "shoulder", obj, gid )  
      AddSlider( "elbow",    obj, gid )  
      AddSlider( "wrist",    obj, gid )  
      
      #AddSlider( "collar",  3001, obj )  
      AddSlider( "hip",      obj, gid )  
      AddSlider( "knee",     obj, gid )  
      AddSlider( "ankle",    obj, gid )  
      AddSlider( "ball",     obj, gid )  
      
      doc.EndUndo()  
      c4d.EventAdd()  
            
      return  
    if __name__=='__main__':  
      main()
    

    -ScottA



  • On 25/10/2016 at 23:08, xxxxxxxx wrote:

    awesome!

    bc[ c4d.DESC_PARENTGROUP ] = c4d.DescID( 0 ) was what was missing from the group description element in my script. It now works as intended

    Thanks Scott. :D


Log in to reply