Best way to hide a child and get best perfomance
-
Hi, forum!
I'm working on a tool the principle of operation of which is similar like a "Sweep". It wraps one "profile" spline around a "path" spline. I want any geometric change to these splines to trigger an update. I think I've figured it out using this code.def GetVirtualObjects(self, op, hh): doc = op.GetDocument() path = op.GetDown() if path is None: return None profile = path.GetNext() if profile is None: return None dirty = op.CheckCache(hh)\ or op.IsDirty(c4d.DIRTY_DATA)\ or path.IsDirty(c4d.DIRTY_DATA)\ or path.IsDirty(c4d.DIRTY_MATRIX)\ or profile.IsDirty(c4d.DIRTY_DATA)\ or profile.IsDirty(c4d.DIRTY_MATRIX) if not dirty: return op.GetCache(hh) path = c4d.utils.SendModelingCommand( c4d.MCOMMAND_CURRENTSTATETOOBJECT, [path], c4d.MODELINGCOMMANDMODE_ALL, c4d.BaseContainer(), doc )[0] profile = c4d.utils.SendModelingCommand( c4d.MCOMMAND_CURRENTSTATETOOBJECT, [profile], c4d.MODELINGCOMMANDMODE_ALL, c4d.BaseContainer(), doc )[0]However, I'd like to hide the child elements, but I can't figure out how I can do it more correctly
I have try use c4d.BaseObject.Touch() and my child is hide, but I can't edit my path/profile dynamically. If I edit the path/profile, I need to refresh the viewport or op settings to see the changes.
I tried this code. Perhaps I didn't fully understand something and missed something.
path = op.GetDown() if path is None: return None profile = path.GetNext() if profile is None: return None path.Touch() profile.Touch() dirty = op.CheckCache(hh)\ or op.IsDirty(c4d.DIRTY_DATA)\ or path.IsDirty(c4d.DIRTY_DATA)\ or path.IsDirty(c4d.DIRTY_MATRIX)\ or profile.IsDirty(c4d.DIRTY_DATA)\ or profile.IsDirty(c4d.DIRTY_MATRIX) if not dirty: return op.GetCache(hh)Besides this, I tried using op.GetAndCheckHierarchyClone like it was in this thread https://developers.maxon.net/forum/topic/10491/13941_hide-child-of-object-plugin/3
path = op.GetDown() if path is None: return None profile = path.GetNext() if profile is None: return None ProfileClone = op.GetAndCheckHierarchyClone(hh, profile, c4d.HIERARCHYCLONEFLAGS_ASSPLINE, False) ProfileCloneDirty = ProfileClone["dirty"] ProfileCloneClone = ProfileClone["clone"] PathClone = op.GetAndCheckHierarchyClone(hh, path, c4d.HIERARCHYCLONEFLAGS_ASSPLINE, False) PathCloneDirty = PathClone["dirty"] PathCloneClone = PathClone["clone"] if not ProfileCloneDirty: return ProfileCloneClone if not PathCloneDirty: return PathCloneClone path_upd = c4d.utils.SendModelingCommand( c4d.MCOMMAND_CURRENTSTATETOOBJECT, [PathCloneClone], c4d.MODELINGCOMMANDMODE_ALL, c4d.BaseContainer(), doc )[0] profile_upd = c4d.utils.SendModelingCommand( c4d.MCOMMAND_CURRENTSTATETOOBJECT, [ProfileCloneClone], c4d.MODELINGCOMMANDMODE_ALL, c4d.BaseContainer(), doc )[0]However, this reduces performance compared to the code above. I would be very grateful if you could help me figure out how I can do this more correctly and optimized.
P.s I think my question will seem primitive, but I'm just learning the API, so don't judge me too harshly
