3
$\begingroup$

I have a noise modifier on a scaling action on a cube. I want to adjust the scale, strength and phase settings of the modifier, for all three axes of the action, with python.

I can add the modifier:

bpy.ops.anim.keyframe_insert_menu(type='Scaling')
bpy.context.area.type = 'GRAPH_EDITOR'
bpy.ops.graph.fmodifier_add(type='NOISE')

but I can't figure out how to access the modifier settings for scale, strength and phase.

$\endgroup$
  • $\begingroup$ Please mark the answer as accepted, click on the check mark beside the answer to toggle it from hollow to green. I removed [solved] from the title. $\endgroup$ – stacker Feb 3 '15 at 8:10
3
$\begingroup$

You shouldn't ever use bpy.ops.anim.keyframe_insert_menu(), it's solely meant for user interface interaction. Use Object.keyframe_insert() (not the operator!) instead.

There's also no reason to use bpy.ops.graph.fmodifier_add(), especially because the dependency on an area type. Use the low-level RNA methods instead:

import bpy

ob = bpy.context.object

ob.keyframe_insert("scale") # ensures animation_data and action are not None
action = ob.animation_data.action

for fcu in action.fcurves:
    if fcu.data_path == "scale":
        mod = fcu.modifiers.new("NOISE")
        mod.scale = 5
$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.