In my script I get access to all selected strips using below code:
selection = [ seq for seq in context.scene.sequence_editor.sequences if seq.select and seq.type == 'SPEED' ]
Now, this gives me a list of speed effects from the selection. I want to modify (basically remove and insert new) the FCurve for the speed_factor
property.
However I can't see how can I access the FCurves for this specific property.
I see than I can access all scene FCurves through bpy.context.scene.animation_data.action.fcurves
. However this seems to have at least two problems:
- I don't know how to properly create
data_path
having onlySpeedControlSequence
instance (the only thing I can think of is some string concatenations, but it doesn't sound like right solution), - even if I had
data_path
value I am looking for I would have to scan through all FCurves for the whole scene to get to the one I want, which doesn't sound very efficient.
How can I access, modify and replace FCurves if I have specific instance of Sequence
?
edit:
One solution seems to be:
seq = # code to get one sequence instance
f = None
for f in bpy.context.scene.animation_data.action.fcurves:
if f.data_path == seq.path_from_id("speed_factor"):
break
else:
f = None
However it seems to be highly inefficient way of approaching that issue. Is there a better way to do it?
data_path
), and you can only optimize it using a dict if you know you'll need to find several F-Curves in the same action (create a lookup dict once with the data_path as key and the F-Curve as value, then access different F-Curves via the key you are after. You may need to add the.array_index
to the key for properties like loc/rot/scale). $\endgroup$