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.