This patch solves a core issue I ran into a couple of times in the past.
I'm not aware of any reliable workaround for addon developersmakes it possible to call operators from within timers reliably.
My main goal is to trigger operator calls fromThe implemented solution is a bit more generic than that, but that's the outside of Blendermain purpose for me.
With this I can build much better and more stable tooling in my vs code extension for Blender.
This patch adds a new api method `Region.exec_operator(operator_name) -> OperatorProperties`.This might not seem like a big deal, but it is the main limitation that stops me from building more
When the method is called, a new event is createdsophisticated tooling in my vs code extension for Blender addon development.
I know that other developers ran into the same limitation as well. This event is later handled during normalI'm not aware of any other reliable
event handling and calls the operator insolution to the correct contextproblem.
With this methodThis patch adds a new api method called `Region.exec_operator(operator_name) -> OperatorProperties`.
It does not call the operator immediately, operators can also be called from timers.but schedules it, Theyso that Blender will just not execute
immediately,execute it in its main
event loop later on. but only the next time Blender is The operator is than executed within the right stateegion the `exec_operator` method
was called on.
You can test the basic functionality of the patch by executing the following in the console:
`C.region.exec_operator("mesh.primitive_plane_add").location = (1, 2, 3)`.
This will create a new plane.
When used from within a script, parameters can be passed to the operator as follows.
This matches the convention we use when creating buttons in the ui.
```
props = region.exec_operator(operator_name)
props.prop1 = ...
props.prop2 = ...
```
I also tested this patch with my vs code extension. It allowed me to execute Python scripts
written in vs code directly in Blender in the right context, without having to "touch" the
Blender window.