3
$\begingroup$

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.

$\endgroup$
3
  • $\begingroup$ You need an access to edit all operators for that. Set two internal BoolPropertys. 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$ Jan 13, 2021 at 9:56
  • $\begingroup$ Also this thread may be helpful. $\endgroup$ Jan 13, 2021 at 10:00
  • $\begingroup$ Thanks. I did see the thread and it seems pretty advanced for me. All my other operators are execute, so it would take a lot of work to convert it all. But this means that I start them all from buttons in the 3dview sidebar panel. Is there a way to detect a click here from inside the modal operator and then cancel it internally? $\endgroup$
    – DrDress
    Jan 13, 2021 at 10:06

1 Answer 1

3
$\begingroup$

What I did was add a condition in my ModalOperator modal() method to return {'FINISHED'} if a certain BoolProperty in my class MyProperties(PropertyGroup) was true. Look into how to make use PointerProperty. Then you can just assign to your boolean variable the value True when you want to stop your modal operator. Let me know if you want me to explain more in detail.

$\endgroup$

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .