@m_adam Thank you for your idea and for even providing a sample code. Simple but brilliant idea to check for the frame difference to see if cinema is playing back. This will help optimize some other scripts of mine and be useful in the future. Side note: I didn't quite understand why in this case i would use the exeCount but it may be helpful in other scripts. I ended up with this and am quite happy with the solution. Thanks again!
import c4d
from c4d import gui
##################################################
# This tag sets all children of the object it is on
# to the layer that object is on.
##################################################
global oldFrame
oldFrame = None
def GetCurrentFrame():
doc = op.GetDocument()
fps = doc.GetFps()
currentFrame = doc.GetTime().GetFrame(fps)
return currentFrame
def main():
global layer, oldFrame
# dont execute if there is no base draw
bd = doc.GetActiveBaseDraw()
if bd is None:
return
# dont execute during playback
currentFrame = GetCurrentFrame()
if currentFrame != oldFrame:
oldFrame = currentFrame
return
# ELSE: Run the rest of the script normally
obj = op.GetObject()
layer = obj.GetLayerObject(doc)
useName = obj[c4d.ID_USERDATA,1]
# option: set objects name to layer name
if layer and useName:
layerName = layer.GetName()
obj.SetName(layerName)
# get all children and sets layer to objects layer
allchildren(obj, obj.GetNext())
def allchildren(obj,next):
while obj and obj != next:
if obj:
obj.SetLayerObject(layer)
allchildren(obj.GetDown(),next)
obj = obj.GetNext()
return True