My nla strip confirmed that the active attribute is True, but bpy.ops.nla.fmodifier_add
failed due to the context is correct
error. What's the reason? For you, I attach my blender work screen and api capture image.
1 Answer
You apparently have to override the context to make Blender believe you are inside the NLA editor.
import bpy
win = bpy.context.window
scr = win.screen
area = [area for area in scr.areas if area.type == 'NLA_EDITOR'][0]
region = area.regions[0]
override = {
'window': win,
'screen': scr,
'area' : area,
'region': region,
'scene' : bpy.context.scene,
}
bpy.ops.nla.fmodifier_add(override, type="STEPPED", only_active=True)
Of course this only works if there is an NLA editor area open. Otherwise you'll have to create one first.
-
$\begingroup$ Thank you, it works perfectly for me. I never knew there was a third hidden parameter. To infer that, I probably need a deeper understanding of Python's inheritance. $\endgroup$ Nov 29, 2021 at 4:04
-
$\begingroup$ If you are interested, please take a look at this question. It's a question about how to add an NLA strip modifier without using ops. $\endgroup$ Nov 29, 2021 at 4:05
-
2$\begingroup$ Having to pretend to be in a particular area is certainly one of the stupider bits of Blender operators. Unfortunately I don't think there's a way to do it without an op here. $\endgroup$– scurestNov 29, 2021 at 4:13