Operator for toggling checkboxes

The “wm.context_toggle” operator is used to toggle checkboxes in the Blender interface. We can configure fast switching of any checkboxes in any windows and panels with this operator.

As an example, let’s configure the checkbox which enables/disables displaying the viewport wireframe.

The “wm.context_toggle” operator takes a text string as its first argument – a pointer to the property described by the checkbox in the Blender Python API.

For the viewport “Wireframe” checkbox this path looks like this:

We can access it with the “wm.context_toggle” operator:

The operator is contextual so to work properly it must be called from the 3D Viewport window context. Also, there is no need to specify the full path with the context specification as “bpy.context.space_data.overlay.show_wireframes”, it is enough to specify only a part after specifying the context.

This operator can be assigned, for example, to a button in a user panel. However, it is much more convenient to use this operator to assign key combinations to quickly switch the desired checkbox.

To associate switching wireframe with a keyboard keycode, in the “Preferences” window in the “KeyMap” section open the “3D View – Object Mode – Object Mode (Global)” list, create a new shortcode with a convenient key combination.

In the “Identifier” field specify the “wm.context_toggle” operator call, and in the field that appears for the “Context Attribute” argument, type the API path to the required property – “space_data.overlay.show_wireframes”.

Now, when pressing the specified keycode in the viewport window, the display of the wireframe on objects will be toggled.

0 0 votes
Article Rating
Notify of
0 Comment
Inline Feedbacks
View all comments