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
    • Register
    • Login

    Show or Hide Object in Viewport

    Cinema 4D SDK
    2024 python
    3
    4
    174
    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.
    • chuanzhenC
      chuanzhen
      last edited by chuanzhen

      Hi,
      I encountered some issues when importing documents and performing hide and display object.

      this is an example c4d file to import --> import.c4d

      this is an example script code:

      
      import c4d
      
      class MyDialog (c4d.gui.GeDialog):
      
          def CreateLayout(self) -> bool:
      
              self.GroupBorderSpace(5, 5, 5, 5)
              self.GroupSpace(5, 5)
              self.AddButton(1000, c4d.BFH_SCALEFIT, name = "import")
              self.AddButton(1001, c4d.BFH_SCALEFIT, name = "show")
              self.AddButton(1002, c4d.BFH_SCALEFIT, name = "hide")
              return True
      
          def Command(self, id, msg):
              if id == 1000:
                  file_path = c4d.storage.LoadDialog()
                  c4d.documents.MergeDocument(doc,file_path,c4d.SCENEFILTER_OBJECTS|c4d.SCENEFILTER_MATERIALS)
                  for obj in doc.GetObjects():
                      obj.ChangeNBit(c4d.NBIT_EHIDE,c4d.NBITCONTROL_SET)
                  c4d.EventAdd()
                  return True
              if id == 1001:
                  for obj in doc.GetObjects():
                      obj.ChangeNBit(c4d.NBIT_EHIDE,c4d.NBITCONTROL_CLEAR)
                  c4d.EventAdd()
                  c4d.DrawViews(c4d.DRAWFLAGS_FORCEFULLREDRAW)
                  return True
              if id == 1002:
                  for obj in doc.GetObjects():
                      obj.ChangeNBit(c4d.NBIT_EHIDE,c4d.NBITCONTROL_SET)
                  c4d.EventAdd()
                  return True
              return True
      
      
      if __name__ == "__main__":
          dlg = MyDialog()
          dlg.Open(c4d.DLG_TYPE_ASYNC, 0, -1, -1, 200, 200)
      

      ui:df043d32-7828-4b64-9aa6-2306499035af-image.png

      Step 1: Use "import" to merge a document into the current document, and then hide the imported object

      Step 2: Use "show" to restore the display of the object, but it will not refresh the display. Only by using the "Redraw" command can the display be refreshed

      Why c4d.EventAdd() and c4d.DrawView() doesn't work, did I miss something?

      It seems to only occur in the document imported for the first time, and when the "show" or "hide" command is used again, it works normally.
      Thanks for any help!

      相信我,可以的!

      gheyretG 1 Reply Last reply Reply Quote 0
      • gheyretG
        gheyret @chuanzhen
        last edited by

        Hi @chuanzhen ,
        This is a Bug and it's already reported, you can find more info in this thread.

        www.boghma.com

        chuanzhenC 1 Reply Last reply Reply Quote 2
        • chuanzhenC
          chuanzhen @gheyret
          last edited by

          @gheyret Thanks for your help!👍
          i use "c4d.CallCommand(12147) # Redraw" to replace c4d.EventAdd() or c4d.Redraw(), it also work!

          change code:

                  if id == 1001:
                      for obj in doc.GetObjects():
                          obj.ChangeNBit(c4d.NBIT_EHIDE,c4d.NBITCONTROL_CLEAR)
                      c4d.CallCommand(12147) # Redraw
                      return True
          

          相信我,可以的!

          1 Reply Last reply Reply Quote 2
          • ferdinandF
            ferdinand
            last edited by ferdinand

            Sorry, I am rotating on the spot right now, did not yet get to answering here. @gheyret is right, there is still a bug, will give @m_adam a note on Monday.

            MAXON SDK Specialist
            developers.maxon.net

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