On 12/12/2017 at 11:14, xxxxxxxx wrote:
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?
On 12/12/2017 at 21:56, xxxxxxxx wrote:
Previously I was using this method:
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:
gch = op.GetAndCheckHierarchyClone(hh, orig, c4d.HIERARCHYCLONEFLAGS_ASPOLY, True)
gchDirty = gch["dirty"]
gchClone = gch["clone"]
if not gchDirty:
# 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().
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:
On 14/12/2017 at 00:59, xxxxxxxx wrote:
Sorry, I just noticed that allchildren is set to True