Optimize GetAndCheckHierarchyClone
-
On 12/12/2017 at 11:14, xxxxxxxx wrote:
Hello plugincafe!
I'm trying to create object plug that will take its child and perform some manipulations with its clone.
This is how the code looks like:** _ 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()_**
** _
**
** _ obj = dic["clone"]**
** _ **
** _ #Modeling commands with obj...**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.
I want to generate new cache only if plugin object or if its child is changed.
Is it possible to optimize this code or I need to use something else?Cheers!
-Merk
-
On 12/12/2017 at 21:56, xxxxxxxx wrote:
Previously I was using this method:
- ** def GetVirtualObjects(self, op, hh) :**
- ** **
- ** child = op.GetDown()**
- ** if not child:**
- ** return**
- **
** - ** dirty = op.CheckCache(hh) or op.IsDirty(c4d.DIRTY_DATA) or child.IsDirty(c4d.DIRTYFLAGS_DATA) or child().IsDirty(c4d.DIRTYFLAGS_MATRIX) or op.GetDown() == None or op.IsDirty(c4d.DIRTYFLAGS_CHILDREN) or child.GetDown() is not None and child.GetDown().IsDirty(c4d.DIRTY_DATA)**
- ** **
- ** if dirty is False: **
- ** op.GetDown().Touch()**
- ** return op.GetCache(hh)**
- ** **
- ** if dirty is True and op.GetDown() : **
- ** op.GetDown().Touch()**
- ** **
- ** if op.GetDown() is None:**
- ** return c4d.BaseObject(c4d.Onull)**
- ** obj = op.GetDown()**
- **
** - ** #Modeling**
This was my first attempt at creating object plugin but the code is not clear at all. I think there should be a better way of optimizing cache.
-
On 13/12/2017 at 22:43, xxxxxxxx wrote:
Download plugin: https://www.dropbox.com/s/mcr652kkt08zx96/Test Plugin 0.3.rar?dl=0
-
On 14/12/2017 at 00:24, xxxxxxxx wrote:
Hi Merk, thanks for writing us.
With reference to your question consider that when you are using the BaseObject::GetAndCheckHierarchyClone() and the dirtiness is false, you're expected to return the "clone" item from the dictionary returned by GetAndCheckHierarchyClone() and not the cache obtained by BaseObject::GetCache() as in the code below:
orig = op.GetDown() if orig is None: return c4d.BaseObject(c4d.Onull) gch = op.GetAndCheckHierarchyClone(hh, orig, c4d.HIERARCHYCLONEFLAGS_ASPOLY, True) gchDirty = gch["dirty"] gchClone = gch["clone"] if not gchDirty: return gchClone # do something else by using the cloned children # ...
It also relevant to note that using the GetCache() in combination with GetAndCheckHierarchyClone() will invalidate the cache object resulting in a non-alive cache whose existence should be forced using the C4DAtom::GetClone().
Best, Riccardo
-
On 14/12/2017 at 00:46, xxxxxxxx wrote:
Thanks for explanation
I have another question regarding this code.
Is it possible to perform modeling operations with gchClone ?
for example, extrude polygons.I tried this code:
- ** def GetVirtualObjects(self, op, hh) :**
- ** orig = op.GetDown()**
- ** if orig is None:**
- ** return c4d.BaseObject(c4d.Onull)**
- ** gch = op.GetAndCheckHierarchyClone(hh, orig, c4d.HIERARCHYCLONEFLAGS_ASPOLY, True)**
- ** gchDirty = gch["dirty"]**
- ** gchClone = gch["clone"]**
- ** if not gchDirty:**
- ** return gchClone**
- ** #Extrude**
- ** settings = c4d.BaseContainer()**
- ** settings[c4d.MDATA_EXTRUDE_OFFSET] = op[10000]**
- ** res = c4d.utils.SendModelingCommand(command = c4d.ID_MODELING_EXTRUDE_TOOL,**
- ** list = [gchClone],**
- ** mode = c4d.MODELINGCOMMANDMODE_POLYGONSELECTION,**
- ** bc = settings,**
- ** doc = op.GetDocument())**
- ** return gchClone**
-
On 14/12/2017 at 00:59, xxxxxxxx wrote:
Sorry, I just noticed that allchildren is set to True