I have a modal operator that runs in the 3d viewport. Its basically the raytracer from the template. It can be canceled with escape.
But I have several other operators which can be executed from panels in the sidebar. This leads to errors if I havent remembered to cancel the modal operator manually.
Can I stop the modal operator automatically from the other operators at the start of the execute method?
Can I remove the modal handle? Or is that bad practice?
This is exactly the same question, but quite old and unresolved. Maybe there is a way now? https://blenderartists.org/t/immediately-cancel-running-modal-operators-from-outside-instance/615499/4
This post addresses the same issue too. Doesn't seem promising, though :-( https://devtalk.blender.org/t/is-there-any-way-to-detect-an-active-modal-operation/7184/4
EDIT: Is there a way to identify from the context or event in the modal method, where the mouse clicked? I guess that there must be some difference whether the viewport was clicked or the sidebar or a different region or space or something. Then I can stop the modal operator internally if I tried to do something I wasn't supposed to do.
BoolProperty
s. The first one should be checked on every loop start of the modal operator and the operator should quit when finds it enabled (other operators should enable it on their start). Another one is for confirming that the modal operator has stopped. It should be enabled in the__del__
method of the modal operator while the first one - disabled back. When other operators find confirmation Property enabled, they disable it back and continue their work. The only thing is all operators have to be modal in this case. $\endgroup$