Hi, I have a python tag on an object that sets the objects children to the same layer as the object. But there is no necessity to execute the python tag every frame during playback. I was wondering how to tell the tag to only execute the main part of the code, when there is a change in the overall hierarchy or better yet: only if the children of the object changes.
It feels like there is a simple solution to this that I am not seeing. I am grateful for any help!
import c4d
from c4d import gui
##################################################
# This tag sets all children of the object it is on
# to the layer that object is on.
##################################################
def main():
global layer
obj = op.GetObject()
# This somehow always return 0, regardless of childrens hierarchy or parameter changes.
print ("children: " + str( obj.GetDirty(c4d.DIRTYFLAGS_CHILDREN) ))
# This also always return 0, regardless of childrens hierarchy or parameter changes.
print ("description: " + str( obj.GetDirty(c4d.DIRTYFLAGS_DESCRIPTION) ))
# This increments by one on basically every click anywhere.
print ("data: " + str( obj.GetDirty(c4d.DIRTYFLAGS_DATA) ))
layer = obj.GetLayerObject(doc)
allchildren(obj, obj.GetNext())
def allchildren(obj,next): # Scan obj hierarchy and set childrens layer
while obj and obj != next:
if obj:
obj.SetLayerObject(layer)
allchildren(obj.GetDown(),next)
obj = obj.GetNext()
return True