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
    • Recent
    • Tags
    • Users
    • Login

    Shorter code for hiding UserData

    Scheduled Pinned Locked Moved PYTHON Development
    5 Posts 0 Posters 438 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 30/05/2014 at 08:08, xxxxxxxx wrote:

      I have a lot of userdata controls that needs show/hide when pressing buttons.
      This is a sample of the code I am using and was wondering if there is maybe a shorter way of coding for this????? 😠

      #--Hide_Cone_Types--
                 if descId[1].id == 14:
                 
                    if Bolt_Fac[c4d.ID_USERDATA,20] == 0:
                        container[c4d.DESC_HIDE] = True
                        Bolt_Fac.SetUserDataContainer(descId, container)
                        
                 #--Hide_Cone_Height--
                 if descId[1].id == 16:
                 
                    if Bolt_Fac[c4d.ID_USERDATA,20] == 0:
                        container[c4d.DESC_HIDE] = True
                        Bolt_Fac.SetUserDataContainer(descId, container)
                        
                 #--Hide_Cone_Radius--
                 if descId[1].id == 18:
                 
                    if Bolt_Fac[c4d.ID_USERDATA,20] == 0:
                        container[c4d.DESC_HIDE] = True
                        Bolt_Fac.SetUserDataContainer(descId, container)
                        
                 #--Hide_Cone_Point_Height--
                 if descId[1].id == 25:
                 
                    if Bolt_Fac[c4d.ID_USERDATA,20] == 0:
                        container[c4d.DESC_HIDE] = True
                        Bolt_Fac.SetUserDataContainer(descId, container)
                        
                 #--Hide_Indented_Height--
                 if descId[1].id == 21:
                 
                    if Bolt_Fac[c4d.ID_USERDATA,20] == 0:
                        container[c4d.DESC_HIDE] = True
                        Bolt_Fac.SetUserDataContainer(descId, container)
                        
                 #---Hide_Dome_Height---
                 if descId[1].id == 23:
                 
                    if Bolt_Fac[c4d.ID_USERDATA,20] == 0:
                        container[c4d.DESC_HIDE] = True
                        Bolt_Fac.SetUserDataContainer(descId, container)

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

        On 30/05/2014 at 08:52, xxxxxxxx wrote:

        Maybe like this.

        hide_items = [
            14, # Hide_Cone_Types
            16, # Hide_Cone_Height
            # ...
        ]
          
        if Bolt_Fac[c4d.ID_USERDATA, 20] == 0:
            for item in hide_items:
                if descId[1].id == item:
                    container[c4d.DESC_HIDE] = True
        

        Or maybe you better use

        hide_items = [
            14, # Hide_Cone_Types
            16, # Hide_Cone_Height
            # ...
        ]
          
        for item in hide_items:
            if descId[1].id == item:
                container[c4d.DESC_HIDE] = (Bolt_Fac[c4d.ID_USERDATA, 20] == 0)
        

        so that the elements will be shown again when UD #20 is not zero.

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

          On 30/05/2014 at 09:01, xxxxxxxx wrote:

          Hi NiklasR. Like I said this is just a sample of the code. There is a code to unhide them thats why I want to put it in a shorter code. 
          Sorry I'm still learning python and would like a sample code pls  😊 
          That's how I'm learning python

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

            On 30/05/2014 at 09:04, xxxxxxxx wrote:

            Thanks NiklasR. Ignore my previous post you rock _<_img src="http://www.c4dcafe.com/ipb/public/style_emoticons/default/thisrocks.gif" border="0" alt=":thisrocks:" title=":thisrocks:" /_>_

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

              On 30/05/2014 at 09:37, xxxxxxxx wrote:

              You're welcome. Sorry I changed my original post for that much. 🙂

              This one's better (in terms of speed)

              hide_items = frozenset([
                  14, # Hide_Cone_Types
                  16, # Hide_Cone_Height
                  # ...
              ])
                
              if descId[1].id in hide_items:
                  container[c4d.DESC_HIDE] = (Bolt_Fac[c4d.ID_USERDATA, 20] == 0)
              

              -Niklas

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