[Noob Question] How to set editor for a command?

Hi guys,
I’ve started learning Python few weeks a go,to make some scripts to automate my workflow a bit.So I’m a beginner.

I want to use the:

bpy.ops.action.select_leftright() command , as well as:

but every time I enter it in the Python console, I get an error - RuntimeError: Operator bpy.ops.action.select_all.poll() failed, context is incorrect

now form what I managed to figure out on my own…that command is editor dependent. So basically the error is telling me that I cannot execute this command while my active editor is the Python Console.

so my question is: How can I set the active editor before executing the command?Because right now I can’t execute the command while having my active editor being the Python Console,and not the timeline.

1 Like

See the code example here:

Hi guys,

I’m having the same problem with the:


command. I’ve looked through the link that @brecht posted and I’m afraid I can’t make sense of it. I am a total noob.

The thing that gets me is, copying the same, working, command from the info console after I’ve manually added a movie to the VSE timeline doesn’t work.

Any help is much appreciated.

Hi Walter,
the issue was that when you run your code…it’s run in the text editor as it’s context.
You need to change the context to the editor you want if you are going to run commands that require context.
If you still can’t figure it out.Let me know…I’ll post the commands I did with the Graph Editor.

1 Like

Hi Okuma_10,

Thanks for your reply. I figured it out and solved my issue. I suppose my main issue was that it’s not very clear what the context is from the documentation. Or rather it’s clear that context is the editor but it’s not clear as to what the syntax is for it.

But thanks to lovely people like yourself and @iss I finally know what the hell I’m doing :slight_smile: …ish

yeah I also was like “W*F is this context thing” when I started. And yeah…documents showed how you could change context,but they weren’t really clear about it as well. Sadly the API is written more like a reference for people who already are somewhat familiar with blender API, rather than a good explanation of what,how,why,where . But once you figured it out…it makes sense.
But if you are trying to get and manipulate data from blender…it’s easier and better to just go right to it and change it, rather than use context dependent commands.
It saves you some code and maybe performance to switch contexts behind the scenes, every time you run your script.

1 Like

It’s worth mentioning that there are edge cases where calling an operator can still fail even though you’re in the correct context. For example, if you try to forcibly invoke bpy.ops.transform.vert_slide from another operator you’ll get an incorrect context error. Luckily you can override a context and pass it to an operator (which is another can of worms entirely), but there’s usually a way to tame the blender API if you’re patient and persistent.