Sometimes it is necessary to register an operator that couldn’t be called by the user directly. For example, if this operator is supposed to be called only by another operator after a series of checks or additional actions.
However, if there is no launch button for such an operator in the UI, the user can still call it by selecting from the list of operators found through the search.
To remove an operator from the search results, we need to specify the “INTERNAL” option in its “bl_options” parameter.
For example, let’s register the simplest operator that adds a default cube to the scene in the common way:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 |
from bpy.types import Operator from bpy.utils import register_class class TEST_OT_add_cube_alt(Operator): bl_idname = 'test.add_cube_alt' bl_label = 'Add Cube Alt' bl_options = {'REGISTER'} def execute(self, context): bpy.ops.mesh.primitive_cube_add() return {'FINISHED'} def register(): register_class(TEST_OT_add_cube_alt) register() |
Such an operator will appear in the search results:
Now let’s add the “INTERNAL” option to it:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 |
from bpy.types import Operator from bpy.utils import register_class class TEST_OT_add_cube_alt(Operator): bl_idname = 'test.add_cube_alt' bl_label = 'Add Cube Alt' bl_options = {'REGISTER', 'INTERNAL'} def execute(self, context): bpy.ops.mesh.primitive_cube_add() return {'FINISHED'} def register(): register_class(TEST_OT_add_cube_alt) register() |
After that, the operator will not be shown in the search results: