PDA

View Full Version : How to update the Timeline with Python?


Scott Ayers
09-20-2010, 10:26 PM
I've started to convert some of my Coffee time line stuff. And one of the things I can't figure out is how to update(refresh) the time line after I've made key changes to the curves.
EventAdd() causes the script to re-run and add keys when I don't want to add them.
So I need another way to refresh the time line at the end of my scripts.

Here's a little example that adds a new key to a curve when I execute the script.
But the new key doesn't show up until I manually move the scrubber: import c4d
def main():
obj = doc.SearchObject("Cube") #Find this object
track = obj.GetFirstCTrack() #Get it's first animation track
if not track: return # if it doesn't have any tracks. End the script
curve = track.GetCurve() #Get the curve for the track found
count = curve.GetKeyCount() #Count how many keys are on it
time = doc.GetTime() #Get the time
frame = time.GetFrame(doc.GetFps()) #Get the FPS

#Adds a new key for the first track. Where the scrubber is located
added = curve.AddKey(time)
print count #prints the total number of keys in the first track

Does anyone know how to force the time line to update in Python so any changes show up immediately without having to do any scrubbing?


-ScottA

Scott Ayers
09-20-2010, 10:46 PM
Doh!
Never mind. I found the problem. I needed to use c4d.EventAdd() instead of EventAdd().
That little c4d. thing always gets me into trouble. :D

Here's the fixed code if anyone is interested: import c4d
def main():
obj = doc.SearchObject("Cube") #Find this object
track = obj.GetFirstCTrack() #Get it's first animation track
if not track: return # if it doesn't have any tracks. End the script
curve = track.GetCurve() #Get the curve for the track found
count = curve.GetKeyCount() #Count how many keys are on it
time = doc.GetTime() #Get the time
frame = time.GetFrame(doc.GetFps()) #Get the FPS

#Adds a new key for the first track. Where the scrubber is located
added = curve.AddKey(time)
print count #prints the total number of keys in the first track
c4d.EventAdd()

-ScottA

sal333
09-23-2010, 01:05 PM
Thanks for the script, Scott.
http://www.qtl.co.il/img/copy.pnghttp://www.google.com/favicon.ico (http://www.google.com/search?q=but%20I%20get%20an%20Attribute%20Error%20when%20I%20execute%20it.%0D%0A%0D%0AAttribute%20Error:%20%20%27None%20Type%27%20object%20has%20no%20attribute%20%27GetFirstCTrack%27.)http://www.qtl.co.il/img/trans.png

CGTalk Moderation
09-23-2010, 01:05 PM
This thread has been automatically closed as it remained inactive for 12 months. If you wish to continue the discussion, please create a new thread in the appropriate forum.