I have a BezierCurve which I'm using to create a camera animation. I've set up a maximum Y Limit to stop the action of the curve on the camera and have set an Influence value of 0.7 to slow down the effect of the change (from moving along the path to stopped):
What I'd like to do is to completely stop the influence of the curve on the camera after a certain frame number. I've found I can do this by setting the Influence value to 1.0 (manually) but I need to animate this change. I can't seem to add a key frame, or a Driver on this setting so I'm trying to do it using Python.
After lots of Googling and cannibalising bits of code I've found without fully understanding it, this is the best I've been able to come up with:
import bpy
bpy.app.handlers.frame_change_pre.clear()
ob = bpy.data.curves["BezierCircle"]
# Is there an animation?
if ob.animation_data is not None and ob.animation_data.action is not None:
action = ob.animation_data.action
# every frame change, this function is called.
def my_handler(scene):
frame = scene.frame_current
if frame<544:
action.type.FModifier.influence = 0.7
else:
action.type.FModifier.influence = 1
bpy.app.handlers.frame_change_pre.append(my_handler)
but obviously it doesn't work, I get
AttributeError: 'Action' object has no attribute 'type'
I just can't get the right syntax to target that FModifier on my curve.
The Blender API seems to suggest that I should be able to use
bpy.types.FModifier(influence) = 0.7
or is it?
bpy.types.FModifier.influence. = 0.7
But then how do I target my BezierCircle ?
Any help much appreciated, I'm only slowly getting up to speed with Blender programming!
UPDATE with fixed code from answer
import bpy
bpy.app.handlers.frame_change_pre.clear()
ob = bpy.data.curves["BezierCircle"]
# debug - v2 iterates through modifiers until it find LIMITS
action = bpy.data.actions.get("BezierCircleAction")
mods = [m for f in action.fcurves if f.data_path == 'eval_time' for m in f.modifiers if m.type == 'LIMITS']
for m in mods:
print(m.influence)
# end debug
# every frame change, this function is called.
def my_handler(scene):
frame = scene.frame_current
if frame<544:
ob.animation_data.action.fcurves[0].modifiers[1].influence = 0.7
else:
ob.animation_data.action.fcurves[0].modifiers[1].influence = 1
bpy.app.handlers.frame_change_pre.append(my_handler)