Interacting with the Timeline
TimelinePanel allows to control the
TimelinePanel.activeComposition, the current
TimelineRow selection and the selected keyframes.
Controlling the time
# Get the user focused timeline panel timeline=project.getLastFocusedTimelinePanel() # Move the timeline to 1 sec timeline.currentTime = Autograph.Timecode(0,0,1,0)
You can react to the timeline’s changes with the
def onTimeChanged(timeline, time): print("The time is now %r" % time) timeline.onCurrentTimeChanged(onTimeChanged)
Get the current rows selection
for row in timeline.getSelectedRows(): # row.model is a tuple [Effect,Param] since each row # can be either an Effect (which could be a layer or generator or modifier) or a Param if row.model: print(row.model.getDisplayName())
You can react to changes made to the selection with
The keyframes selection is also available with
Saving the current selection to JSON
You can save the selected row with
TimelinePanel.getClipboardFromSelection() or even with an arbitrary list of rows and keyframes with
TimelineClibpoard can then be saved to JSON with
It can also be stored in the Operating System’s clipboard with
This is useful to paste the JSON text in a text editor and save it somewhere.
To load from a JSON string, you can use
TimelinePanel.getClipboardFromSystem() or directly construct a
TimelineClipboard from the string.
Finally, to apply a clipboard to the current timeline selection, you can use
timeline.getClipboardFromSelection().storeInSystemClipboard() ... timeline.applyClipboardToSelection(timeline.getClipboardFromSystem())
Mapping time to Params
When accessing keyframes on a
Param (e.g: using
DoubleParamBase.getValue() or directly using
Curve), the time is always expressed in seconds, in a time-space local to the parameter.
If a layer has a time-offset or has been time-stretched, the local time of any
Param on a layer is no longer the same time as the timeline’s time.
If you need to programmatically change values on a
Param at the current
TimelinePanel.currentTime, you will need to first map it to the Param local time using:
If you need to map keyframes of a Param to their actual time on the timeline, you need to apply the inverse mapping:
keyframes = param.getCurve().getKeyFrames() for k in keyframes: keyTimelineTime=timeline.mapParamTimeToTimeline(param, k.time)