Can a blender addon intercept a blender function?
I was looking to open issues and looked to this one:
If local view is toggled, that it turns off grid decorations. #6257
Is it possible for a blender addon to intercept a blender function?
If it is possible, do you know where in Bonsai one can register a callback function for such action?
Thanks!
Comments
Short answer no. You cannot trigger or override another operator (especially built-in).
There are way around it though, you can create your own operator and override the hotkey instead and place it in the menu next to the built-in function. Or you can check for certain things in a decorator. Or a depsgraph update handler. Or certain properties can be subscribed using the msgbus (like active object).
That bug is probably erroneously marked as first time contributor because it's probably a bit trickier to know how to detect this state.
Understood. I have taken a look to some examples within the Bonsai source code and come up with something to create the operator.
I have filled a PR for it ( If local view is toggled, that it turns off grid decorations. #6257 #6335 ). I do not know if these are the right places:
"
As a side effect, if nothing is selected the shortcut provides a fast way to toggle the grid decorations on/off
What if you just detect local view https://blender.stackexchange.com/questions/51854/how-can-i-detect-global-local-view-via-python in the grid decorator?
I'm also wondering whether it even is a good idea to hide grids in local view. What about other decorators, like solar analysis? Or georeferencing?
I agree, probably the operator view3d.localview_custom should not override the hotkey. In fact a hotkey to toggle the grid is just one click away from #6257 and probably a simple solution.
Anyhow, thanks a lot for explaining the possibilities regarding operators and hotkeys!
Just to iterate I would not try to mess with operators, you should be able to know if a 3D viewport is in local view with https://docs.blender.org/api/current/bpy.types.SpaceView3D.html#bpy.types.SpaceView3D.local_view