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

    Hide DescElements R18

    Scheduled Pinned Locked Moved PYTHON Development
    15 Posts 0 Posters 1.5k 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 28/11/2016 at 07:40, xxxxxxxx wrote:

      Hey Andreas,

      thx alot 🙂
      Your reply makes me antsy and I hope I can finish my current job soon to take a look into that stuff.

      Ill be back ... soon
      rownn

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

        On 28/11/2016 at 11:51, xxxxxxxx wrote:

        Ok, I don´t get it.

        import os  
        import math  
        import sys  
        import c4d  
          
        from c4d import plugins, utils, bitmaps, gui  
          
        PLUGIN_ID = 123446789  
          
        class GUItest(plugins.ObjectData) :  
          
          def InitA(self, op, type, id, value) :  
              self.InitAttr(op, type, [id])  
              op[id] = value  
          
          def Init(self, op) :  
              self.InitA(op, bool, c4d.GT_HIDE01, False)  
              self.InitA(op, float, c4d.GT_REAL, 12)  
          
              return True  
                
          
          def GetDDescription(self, node, description, flags) :  
          
              if not description.LoadDescription(node.GetType()) : return False  
          
              singleID = description.GetSingleDescID()  
              groupID = c4d.DescID(c4d.DescLevel(c4d.GT_GROUP1, c4d.DTYPE_GROUP, node.GetType()))  
          
              if singleID:  
                  if singleID[0].id == c4d.GT_REAL:  
                      bc = c4d.GetCustomDataTypeDefault(c4d.DTYPE_REAL)  
          
                      if c4d.GT_HIDE01: bc.SetBool(c4d.DESC_HIDE, True)  
                      else: bc.SetBool(c4d.DESC_HIDE, False)  
          
                      description.SetParameter(singleID, bc, groupID)  
          
              return (True, flags | c4d.DESCFLAGS_DESC_LOADED)  
          
          
          def GetVirtualObjects(self, op, hierarchyhelp) :  
              return None  
          
          
        if __name__ == "__main__":  
          dir, file = os.path.split(__file__)  
          icon = bitmaps.BaseBitmap()  
          icon.InitWith(os.path.join(dir, "res", "Icon_Default.png"))  
          plugins.RegisterObjectPlugin(id=PLUGIN_ID, str="GUItest",  
                                      g=GUItest,  
                                      description="GUItest", icon=icon,  
                                      info=c4d.OBJECT_GENERATOR)
        
        1 Reply Last reply Reply Quote 0
        • H Offline
          Helper
          last edited by

          On 29/11/2016 at 08:40, xxxxxxxx wrote:

          Here's an example:

            
          #This is an example how to hide node based descriptions using the GetDDescription() method added in R18  
          #The GetDEnabling() method added in R15 is used here to grey out the descriptions if desired  
            
          import c4d  
          from c4d import bitmaps, documents, plugins  
            
          PLUGIN_ID = 100000   #Be sure to use a unique ID obtained from www.plugincafe.com  
            
          class MyObject(plugins.ObjectData) :  
            
            def Init(self, node) :  
            
                data = node.GetDataInstance()                  
                data.SetBool(1111, False);  
                data.SetString(2222, "default");  
            
                return True          
            
            def GetDDescription(self, node, description, flags) :  
            
                data = node.GetDataInstance()  
            
                #load the parameters from the description resource  
                if not description.LoadDescription(node.GetType()) : return False  
            
                singleID = description.GetSingleDescID()          
            
                ### Use this code block to hide/unhide the gizmo depending on the state of the checkbox gizmo ###  
                #groupID = c4d.DescID(c4d.DescLevel(c4d.ID_OBJECTPROPERTIES, c4d.DTYPE_GROUP, node.GetType()))  #The default group  
                groupID = c4d.DescID(c4d.DescLevel(1000, c4d.DTYPE_GROUP, node.GetType()))  
                paramID = c4d.DescID(c4d.DescLevel(2222))  
                if singleID is None or paramID.IsPartOf(singleID)[0]:  
                    bc = c4d.GetCustomDataTypeDefault(c4d.DTYPE_STRING)  
                    bc.SetString(c4d.DESC_NAME, "My String")  
                    if data.GetBool(1111) == True: bc.SetBool(c4d.DESC_HIDE, True)  
                    if data.GetBool(1111) == False: bc.SetBool(c4d.DESC_HIDE, False)  
                    if not description.SetParameter(paramID, bc, groupID) : return False  
                      
             
                #Shorter version using GetParameterI() if preferred  
                #bc = description.GetParameterI(paramID, None)      
                #if data.GetBool(1111) == True: bc.SetBool(c4d.DESC_HIDE, True)  
                #if data.GetBool(1111) == False: bc.SetBool(c4d.DESC_HIDE, False)  
             
            
                #Use this to change the text in the string gizmo depending on the state of the checkbox gizmo   
                if data.GetBool(1111) == True: data.SetString(2222, "")  
                else: data.SetString(2222, "Not default")              
                  
                return (True, flags | c4d.DESCFLAGS_DESC_LOADED)  
                  
            #Use this to grey out the string type gizmo if the checkbox is enabled  
            """def GetDEnabling(self, node, id, t_data, flags, itemdesc) :  
            
                data = node.GetDataInstance()  
                  
                paramID = id[0].id  
                  
                if data.GetBool(1111) == True:   
                    if paramID == 2222: return False  
                else:   
                    if paramID == 2222: return True  
            
                return True"""  
            
            
            def GetBubbleHelp(self, node) :  
                return "Plugin Bubble Help"  
            
          if __name__ == "__main__":  
            plugins.RegisterObjectPlugin(id=PLUGIN_ID, str="Hide/disable Description",  
                                         g=MyObject,  
                                         description="myobject", icon=bitmaps.InitResourceBitmap(c4d.Onull),  
                                         info=c4d.OBJECT_GENERATOR)  
            
             
          ### .res file ###  
            
          CONTAINER myobject  
          {  
            NAME myobject;  
            INCLUDE Obase;  
            
            //Use this for the default group  
            //GROUP ID_OBJECTPROPERTIES  
            //{  
            //    BOOL MY_CHECKBOX { }  
            //    STRING MY_STRING { }  
            //}  
              
            GROUP MY_GROUP  
            {  
                DEFAULT 1;  //Makes is open by default  
                BOOL MY_CHECKBOX { }  
                STRING MY_STRING { }  
            }  
          }  
            
            
          ### .h file ###  
            
          #ifndef _myobject_H_  
          #define _myobject_H_  
            
          enum  
          {   
            MY_GROUP         = 1000,  
            MY_CHECKBOX      = 1111,  
            MY_STRING        = 2222,  
          };  
            
          #endif  
            
            
          ### .str file ###  
            
          STRINGTABLE myobject  
          {  
            myobject              "Hide/disable Attributes";  
              
            MY_GROUP              "My Group Tab";     
            MY_CHECKBOX           "Toggle Me";  
            MY_STRING             "My String";      
          }  
          

          -ScottA

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

            On 29/11/2016 at 13:23, xxxxxxxx wrote:

            HeyScott

            thank you! Now it works and I´m able to do alot of funny stuff.

            def GetDDescription(self, node, description, flags) :  
              data = node.GetDataInstance()  
              
              if not description.LoadDescription(node.GetType()) : return False  
              
              singleID = description.GetSingleDescID()  
              groupID = c4d.DescID(c4d.DescLevel(c4d.GT_GROUP1, c4d.DTYPE_GROUP, node.GetType()))  
              paramID = c4d.DescID(c4d.DescLevel(c4d.GT_REAL))  
              
              if singleID is None or paramID.IsPartOf(singleID)[0]:  
                  bc = c4d.GetCustomDataTypeDefault(c4d.DTYPE_REAL)  
                  if data.GetBool(c4d.GT_HIDE01) == True: bc.SetBool(c4d.DESC_HIDE, True)  
                  elif data.GetBool(c4d.GT_HIDE01) == False:  
                      bc.SetString(c4d.DESC_NAME, "Real")  
                      bc.SetLong(c4d.DESC_UNIT, c4d.DESC_UNIT_METER)  
                      bc.SetBool(c4d.DESC_HIDE, False)  
                  if not description.SetParameter(paramID, bc, groupID) : return False  
              
              return (True, flags | c4d.DESCFLAGS_DESC_LOADED)
            

            But one of many questions and one note.

            Question:
            If I use

            if c4d.GT_HIDE01: ... 
            

            instead of

            if data.GetBool(c4d.GT_HIDE01) == True: ... 
            

            nothing happens. Why?

            Note:
            If I print paramID.IsPartOf(singleID) cinema crashs.

            Thanks Andreas and Scott and greetings
            rownn

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

              On 29/11/2016 at 14:00, xxxxxxxx wrote:

              The code "if c4d.GT_HIDE01:" asks the question: if this integer.
              But C4D doesn't know what that means without some context.
              So you need to tell C4D to look in the node's container for that integer ( node.GetDataInstance() ).
              That's what the "data" variable is used for in my example.

              It might have been clearer if I named it "bc" or maybe something like "nodeBC".
              I tend to use "data" by habit.

              -ScottA

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

                On 30/11/2016 at 05:38, xxxxxxxx wrote:

                Damn! I used c4d.GT_HIDE01 instead of node[c4d.GT_HIDE01]. That´s embarrassing!!

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

                  On 30/11/2016 at 10:22, xxxxxxxx wrote:

                  Hi guys,

                  glad you seem to have solved the issue already.
                  I just want to add, that there's a slight difference between creating a new parameter description and changing an existing one in GetDDescription().
                  In the posted snippets it looks like you are creating a new description parameter. At least you are always overwriting the existing description parameter. It's a bit hard to tell, without seeing the resource files. In Scott's example this is definitely the case, if I'm not mistaken.
                  You can do so, but in such a case, where you have defined a description parameter in a resource file and just want to hide it, the approach would be slightly different. Instead of creating a new BaseContainer (and then having to care to set up everything the way you want, while you already did so before in the resource file) with GetCustomDataTypeDefault(), you'd rather use Description.GetParameterI() to get the existing BaseContainer of the parameter description and simply modify the needed value (e.g. in this case DESC_HIDE).

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

                    On 30/11/2016 at 13:35, xxxxxxxx wrote:

                    Hey Andreas,

                    thx for that point. It would be nice to hide an element without the need to reset everything else, but Description.GetParameterI( id , ar ) crashs cinema, too.

                    def GetDDescription(self, node, description, flags) :  
                      
                          data = node.GetDataInstance()  
                      
                          if not description.LoadDescription(node.GetType()) : return False  
                      
                          singleID = description.GetSingleDescID()  
                          groupID = c4d.DescID(c4d.DescLevel(c4d.GT_GROUP1, c4d.DTYPE_GROUP, node.GetType()))  
                          paramID = c4d.DescID(c4d.DescLevel(c4d.GT_REAL))  
                      
                          if singleID is None or paramID.IsPartOf(singleID)[0]:  
                              bc = description.GetParameterI(paramID, []) #c4d.GetCustomDataTypeDefault(c4d.DTYPE_REAL)  
                              if node[c4d.GT_HIDE01]: bc[c4d.DESC_HIDE] = True  
                              elif not node[c4d.GT_HIDE01]: bc[c4d.DESC_HIDE] = False  
                              if not description.SetParameter(paramID, bc, groupID) : return False  
                      
                          return (True, flags | c4d.DESCFLAGS_DESC_LOADED)
                    
                    1 Reply Last reply Reply Quote 0
                    • H Offline
                      Helper
                      last edited by

                      On 30/11/2016 at 15:07, xxxxxxxx wrote:

                      Try using None instead of "[]" in your GetParameterI() function.

                      I added the GetParameterI() version to my example.

                      -ScottA

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

                        On 01/12/2016 at 02:34, xxxxxxxx wrote:

                        Hey,

                        Ive already tried using None, but with None cinema freezes.

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

                          On 01/12/2016 at 07:25, xxxxxxxx wrote:

                          Since bc is assigned to GetParameterI() in your code. It will probably crash when it's used in the SetParameter() function.
                          Try it without using SetParameter() at the end. It doesn't seem to be needed when using the  GetParameterI() function to change a description.

                          Like this:

                          bc = description.GetParameterI(paramID, None)      
                          if data.GetBool(1111) == True: bc.SetBool(c4d.DESC_HIDE, True)  
                          if data.GetBool(1111) == False: bc.SetBool(c4d.DESC_HIDE, False)
                          

                          -ScottA

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

                            On 01/12/2016 at 09:04, xxxxxxxx wrote:

                            Yep, Scott is right. Sorry, I forgot to tell yesterday.
                            But still, it shouldn't crash C4D. We are investigating.

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

                              On 02/12/2016 at 04:40, xxxxxxxx wrote:

                              Thank you guys,

                              I though I had tried to uncomment that line, because it makes totally sense. Hmm...
                              Finally the code looks clean and works. I like such a finish.

                              def GetDDescription(self, node, description, flags) :  
                                
                                if not description.LoadDescription(node.GetType()) : return False  
                                
                                singleID = description.GetSingleDescID()  
                                paramID = c4d.DescID(c4d.DescLevel(c4d.GT_REAL))  
                                
                                if singleID is None or paramID.IsPartOf(singleID)[0]:  
                                    bc = description.GetParameterI(paramID, None)   
                                    if node[c4d.GT_HIDE01]: bc[c4d.DESC_HIDE] = True  
                                    else: bc[c4d.DESC_HIDE] = False  
                                
                                return (True, flags | c4d.DESCFLAGS_DESC_LOADED)
                              

                              thx again
                              rownn

                              PS: Thanks 1M times all the guys who implemented that great possibility.

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