# How to add Modifier to an NLA strip using Python?

Unlike objects, NLA strips do not seem to have the modifiers.new() method. Instead, there was a bpy.ops.nla.fmodifier_add(), so I tried to activate the strip to use it, but it was difficult. The active was a read-only property.

So unwillingly, after clicking the strip in the GUI to confirm that the active value was true, the ops was executed, but the incorrect context error was obtained.

What is the correct way to add Modifier to the NLA strip using Python without clicking GUI?

With the blender 3.0 update, the modifier of NLA strip is no longer read-only. [Release note]

The command is strip.modifiers.new('your name here', 'STEPPED') documented here. The below example adds a modifier to the currently selected strip.

# get the currently selected strip
cur_strip = bpy.context.scene.sequence_editor.active_strip

# add a modifier to the strip
new_modifier = cur_strip.modifiers.new('your name here', 'STEPPED')


Also, you're getting the failed, context is incorrect error message because I believe all the bpy.ops.XXX commands need to be run while the mouse is in the correct area (in this case, the video editor). Since your mouse is in the scripting console, it errors. So you would need to run the below command. Unfortunately usually doing something in the video editor, then looking at the command in the scripting console gives you the non-console friendly bpy.ops.XXX version of the command.

bpy.context.area.type = 'SEQUENCE_EDITOR';<your command here>;bpy.context.area.type = 'CONSOLE'


I'm using Blender 3.0, I don't know if its different in Blender 2.X