Deleting animation tracks for Shader Effector
-
On 14/09/2013 at 15:08, xxxxxxxx wrote:
I am trying to delete all animation tracks in the document.
The following code successfully removes all tracks except those under "Shader Properties" in the shader effector objects—for instance, the gradient property. Do I need to access these particular tracks through some other means? Are these tracks somehow different from the others?
Thanks.
import c4d
from c4d import documentsdef GetNextObject(obj) :
if obj==None:
return None
if obj.GetDown() :
return obj.GetDown()
while not obj.GetNext() and obj.GetUp() :
obj = obj.GetUp()
#print (obj)
return obj.GetNext()def RemoveTracks(obj) :
for track in obj.GetCTracks() :
#if (track.GetCurve().GetKeyCount() > 0) :
track.Remove()
def main() :
obj = doc.GetFirstObject()
if obj==None: return
while obj:
RemoveTracks(obj)
obj = GetNextObject(obj)
c4d.EventAdd()
if __name__=='__main__':
main() -
On 14/09/2013 at 16:22, xxxxxxxx wrote:
I am not sure how this is meant. You are stepping though all BaseObjects in the document
and remove all CTracks containing at least one Ckey. A BaseShader is obviously not a BaseObject
and therefore it will not get covered. -
On 14/09/2013 at 22:10, xxxxxxxx wrote:
Thank you. That was very helpful.
Here is the updated code for anyone else who might have this issue.
import c4d
from c4d import documentsdef GetNextObject(obj) :
if obj==None:
return None
if obj.GetDown() :
return obj.GetDown()
while not obj.GetNext() and obj.GetUp() :
obj = obj.GetUp()
return obj.GetNext()def RemoveTracks(obj) :
for track in obj.GetCTracks() :
#if (track.GetCurve().GetKeyCount() > 0) :
track.Remove()
shader = obj.GetFirstShader()
shadertree(shader)def shadertree(shader) :
while(shader) :
shaderTracks = shader.GetCTracks()
for shaderTrack in shaderTracks:
shaderTrack.Remove()
# Check for child shaders
if shader.GetDown() : shadertree(shader.GetDown())
# Get the next shader
shader = shader.GetNext()def main() :
obj = doc.GetFirstObject()
if obj==None: return
while obj:
RemoveTracks(obj)
obj = GetNextObject(obj)
c4d.EventAdd()
if __name__=='__main__':
main()