On 11/12/2017 at 19:05, xxxxxxxx wrote:
I'm using this code by gr4ph0s in my object plugin:
def GetVirtualObjects(self, op, hh) :
first = op.GetDown()
if not first: return
dic = op.GetAndCheckHierarchyClone(hh, first, c4d.HIERARCHYCLONEFLAGS_ASPOLY, False)
if not dic["dirty"] and not op.IsDirty(c4d.DIRTY_DATA) and op.GetCache() :
return op.GetCache().GetClone() #Do not know why op.GetCache() fail sometime but returning a cloned works like a charm !
#If we are here that mean something has changed so we need to rebuild everythings.
obj = dic["clone"]
#Do some stuff on your Obj for example an extrude, Keep in mind
bs = obj.GetPolygonS()
settings = c4d.BaseContainer() # Settings
settings[c4d.MDATA_EXTRUDE_OFFSET] = 50.0 # Length of the extrusion
res = c4d.utils.SendModelingCommand(command = c4d.ID_MODELING_EXTRUDE_TOOL,
list = [obj],
mode = c4d.MODELINGCOMMANDMODE_POLYGONSELECTION,
bc = settings,
doc = obj.GetDocument())
I read in docs that GetAndCheckHierarchyClone will generate new cache if something is changed but it constantly generates new cache even if nothing is changed in object plugin or in its child object.
Previously I was using this code:
child = op.GetDown() if not child: return dirty = op.CheckCache(hh) or op.IsDirty(c4d.DIRTY_DATA) or child.IsDirty(c4d.DIRTYFLAGS_DATA) if dirty is False: return op.GetCache(hh)
I tried to apply this code in conjunction with gr4ph0s' version but it hides plugin's child object only if I'm changing something in a hierarchy and if nothing is changed, the child object is visible.
is it possible to optimize the code so it could generate cache only if something in changed?