Maxon Developers Maxon Developers
    • Documentation
      • Cinema 4D Python API
      • Cinema 4D C++ API
      • Cineware 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

    Visibility Toggle

    Cinema 4D SDK
    4
    6
    1.3k
    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.
    • mrpinouxM
      mrpinoux
      last edited by m_adam

      I'm adding a script, added as a valuable shortcut in my everyday workflow here :

      It basically allows you to select any object, and assigned to the letter H, Hide or Reveal your selected object. Like in Maya. Very Useful.

      Not sure it is the best way to do it, that's why I'm posting it here.

      import c4d
      from c4d import gui
      
      def main():
      
          allobj = doc.GetActiveObjects(c4d.GETACTIVEOBJECTFLAGS_CHILDREN)
          obj = object()
          for obj in allobj:
              editor = obj[c4d.ID_BASEOBJECT_VISIBILITY_EDITOR]
              render = obj[c4d.ID_BASEOBJECT_VISIBILITY_RENDER]
      
              if editor == 1 or render == 1:
                  newstate = 2
              else:
                  newstate = 1
      
              obj[c4d.ID_BASEOBJECT_VISIBILITY_EDITOR] = newstate
              obj[c4d.ID_BASEOBJECT_VISIBILITY_RENDER] = newstate
      
      
      if __name__=='__main__':
          main()
          c4d.EventAdd()
      
      
      1 Reply Last reply Reply Quote 0
      • P
        PluginStudent
        last edited by

        The line

        obj = object()
        

        is useless.

        And to handle editor and render visibility, can can use dedicated functions: GetEditorMode(), GetRenderMode(), etc. and the explicit values c4d.MODE_ON, c4d.MODE_OFF, and c4d.MODE_UNDEF.

        See also the C++ docs: BaseObject Manual

        1 Reply Last reply Reply Quote 0
        • ManuelM
          Manuel
          last edited by Manuel

          hi,
          thanks @PluginStudent 🙂

          you can do shorter by doing a module (%) and add one. (instead of 0-1 you will return 1-2)
          Also obj = object() is not necessary as you define it in the loop after.

          import c4d
          from c4d import gui
          
          def main():
          
              allobj = doc.GetActiveObjects(c4d.GETACTIVEOBJECTFLAGS_CHILDREN)
              for obj in allobj:
                  obj[c4d.ID_BASEOBJECT_VISIBILITY_EDITOR] = obj[c4d.ID_BASEOBJECT_VISIBILITY_EDITOR] % 2 + 1
                  obj[c4d.ID_BASEOBJECT_VISIBILITY_RENDER] = obj[c4d.ID_BASEOBJECT_VISIBILITY_RENDER] % 2 + 1
          
          
          if __name__=='__main__':
              main()
              c4d.EventAdd()
          
          

          or

          import c4d
          from c4d import gui
          
          def main():
          
              allobj = doc.GetActiveObjects(c4d.GETACTIVEOBJECTFLAGS_CHILDREN)
              for obj in allobj:
                  obj.SetEditorMode(obj.GetEditorMode() % 2 + 1)
                  obj.SetRenderMode(obj.GetRenderMode() % 2 + 1)
          
          
          if __name__=='__main__':
              main()
              c4d.EventAdd()
          
          

          Cheers,
          Manuel

          MAXON SDK Specialist

          MAXON Registered Developer

          1 Reply Last reply Reply Quote 0
          • ManuelM
            Manuel
            last edited by

            hi,

            without any feedback from you, I'll set this thread as solved tomorrow

            Cheers,
            Manuel

            MAXON SDK Specialist

            MAXON Registered Developer

            1 Reply Last reply Reply Quote 0
            • W
              WDP
              last edited by Manuel

              Hello tried the script it switches from off to undef, how do I switch from off to on?


              import c4d
              from c4d import gui
              
              def main():
              
                  allobj = doc.GetActiveObjects(c4d.GETACTIVEOBJECTFLAGS_CHILDREN)
                  for obj in allobj:
                      obj.SetEditorMode(obj.GetEditorMode() % 2 + 1)
                      obj.SetRenderMode(obj.GetRenderMode() % 2 + 1)
              
              
              if __name__=='__main__':
                  main()
                  c4d.EventAdd()
              

              and how do i add the key frame?

              Thank you very much!

              1 Reply Last reply Reply Quote 0
              • ManuelM
                Manuel
                last edited by

                hi,

                you already opened this thread, asking for the question, I've answer there. Please, stop asking the same question on different threads and continu on the linked one.

                Cheers,
                Manuel

                MAXON SDK Specialist

                MAXON Registered Developer

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