OBJECT GENERATOR and User Data



  • On 04/01/2017 at 13:37, xxxxxxxx wrote:

    Hello there,

    I have two questions concerning the script below:

    import c4d, os  
    from c4d import plugins, bitmaps  
      
    PLUGIN_ID = 1938333  
      
    def CreateUDGroup(obj, name, parentGroup=None, columns=None, titlebar=1, shortname=None) :  
      ...         
        
    def CreateUDText(obj, name, parentGroup=None, CustomGUI=None, val=None, shortname=None) :  
      ...  
      
    class Text(plugins.ObjectData) :      
      def GetVirtualObjects(self, op, hierarchyhelp) :  
          **UD = op.GetUserDataContainer()  
          if UD == [] :**  
              TexelGroup = CreateUDGroup(op,"Text",c4d.DescID(0))  
              text = CreateUDText(op,"Text", TexelGroup, c4d.CUSTOMGUI_STRINGMULTI, "Text")  
        
    if __name__ == "__main__":  
      dir, file = os.path.split(__file__)  
      help = ""  
      icon = bitmaps.BaseBitmap()  
      icon.InitWith(os.path.join(dir, "res", "Text.tif"))  
      plugins.RegisterObjectPlugin(id=PLUGIN_ID, str="Text",  
                                  g=Text,  
                                  description="TGP", icon=icon,  
                                  info=c4d.OBJECT_GENERATOR)
    

    Frst question : when the object "Text" is generated the default opened menu is "Basic", How I can set the menu "Text" to default. (See screenshot below)

    Second question: I have added the condition   below  to prevent the adding user data every time when I select my object in object manager.

    UD = op.GetUserDataContainer()  
    if UD == [] :
    

    Is there other way to do that?

    Thanks.



  • On 04/01/2017 at 15:34, xxxxxxxx wrote:

    For your second question GetUserDataContainer() Always return a list. So your syntax is equivalent to

    if isinstance(UD, list) :
    

    So for your need just make

    if not len(UD) :
    #doing if not is like if len(UD) == 0 but quicker to write
    

    About the first one it must be possible but not sure wait for another people :)



  • On 04/01/2017 at 16:07, xxxxxxxx wrote:

    Thanks Bro! 👍



  • On 05/01/2017 at 07:04, xxxxxxxx wrote:

    Hi,

    Adding user data to an Object in ObjectData.GetVirtualObjects() isn't a common worklow.
    Why not use normal parameters defined in resource instead?



  • On 05/01/2017 at 10:13, xxxxxxxx wrote:

    Originally posted by xxxxxxxx

    Hi,

    Adding user data to an Object in ObjectData.GetVirtualObjects() isn't a common worklow.
    Why not use normal parameters defined in resource instead?

    I don't know how I can do that.
    Have you any idea concerning the first question?
    Thanks.



  • On 05/01/2017 at 12:23, xxxxxxxx wrote:

    There is an SDK plugin example called Py_RoundedTube that uses resources for the plugin's attributes that you can look at for references.

    As for User Data. The c4d.DESC_DEFAULT id can be used to set the active tab.
    Here's a short example of that in a script:

    #This is how to change the UserData tab to a different name  
    #The TAB will be the topmost group. So any gizmos will need to reference it using: GetUserDataContainer()[0][0]  
      
    import c4d  
    def main() :  
      
      obj = doc.GetActiveObject()  
      if not obj: return False  
        
      #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 Group"            #<---The text displayed in the TAB instead of UserData  
      Groupbc[c4d.DESC_TITLEBAR] = True  
      obj.AddUserData(Groupbc)  
      
      Groupbc[c4d.DESC_DEFAULT] = True    #Makes this new AM tab selected  
        
      #Puts a Real type UD entry into this group  
      Grp_Item = c4d.GetCustomDatatypeDefault(c4d.DTYPE_REAL)  
      Grp_Item[c4d.DESC_NAME] = "My Real"  
      Grp_Item[c4d.DESC_PARENTGROUP] = obj.GetUserDataContainer()[0][0]  
      obj[obj.AddUserData(Grp_Item)] = 55.6      
      
      c4d.EventAdd()  
      
    if __name__=='__main__':  
      main()
    

    -ScottA



  • On 15/03/2017 at 21:02, xxxxxxxx wrote:

    Hi,

    Is the first question solved?

    Ching



  • On 16/03/2017 at 03:56, xxxxxxxx wrote:

    Originally posted by xxxxxxxx

    Is the first question solved?

    The first question was:

    Originally posted by xxxxxxxx

    when the object "Text" is generated the default opened menu is "Basic", How I can set the menu "Text" to default.

    It doesn't make sense and also there's no way to change the "Basic" tab page title.
    This tab is handled by Cinema in the base list resource and this is the standard title.



  • On 16/03/2017 at 08:20, xxxxxxxx wrote:

    Hi,Yannick.

    In the past,I also think that there is no way to change. but  recently, I saw a lot of .res files,I changed my view. In fact,it can change through .res file,as long as we add an "DEFAULT 1;" to the  group,like this:

      
    CONTAINER Oeselectionmap  
    {  
      NAME    Oeselectionmap;  
      INCLUDE Obase;  
      
      GROUP        SELECTION_EFFECTOR_GROUPEFFECTOR  
      {  
           DEFAULT 1;  
      
          REAL    SELECTION_EFFECTOR_STRENGTH  
          {  
              MIN 0.0;  
              MAX 100.0;  
              MINSLIDER 0.0;  
              MAXSLIDER 100.0;  
              UNIT      PERCENT;  
              CUSTOMGUI REALSLIDER;  
          }  
    

    Best wishes!
    Ching



  • On 17/03/2017 at 08:10, xxxxxxxx wrote:

    Sorry, I misunderstood the initial question.
    It was about changing the active tab page to a user data group, which was created in an object plugin's GetVirtualObjects().
    But it's not recommended to add user data to an object plugin in its GetVirtualObjects(). Also it does not make sense to change the GUI from such function.

    As you found, this can be done with the DEFAULT flag in a description resource.
    Also, if not in a node plugin, c4d.gui.ActiveObjectManager_SetObject() can be used to set the active object/material/tag etc. in the Attribute Manager and its selected page.


Log in to reply