Show or Hide Object in Viewport
-
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)
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! -
Hi @chuanzhen ,
This is a Bug and it's already reported, you can find more info in this thread. -
@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
-