Outcome
Draw a Cursor pivot action that looks pressed whenever Blender’s current pivot is already Cursor:
ts = C.scene.tool_settings; operator(L, "wm.context_set_enum", text="Cursor", depress=ts.transform_pivot_point == "CURSOR", data_path="scene.tool_settings.transform_pivot_point", value="CURSOR")The state check runs while PME draws the menu. Blender’s public wm.context_set_enum operator runs only after the user clicks the button.
Build the button from one source of truth
- Identify the Blender property that owns the real state. Here it is
C.scene.tool_settings.transform_pivot_point. - Add a Custom item to the PME menu.
- Read the property once for the visible state.
- Pass a Boolean comparison to
depress=. - Make the deferred operator change that same property.
The important contract is that display and action agree:
pressed state reads property A
click action writes property AIf the button reads one property but changes another, it can look active while its intended action is not.
Show a different label or icon by state
The same Custom item can derive its presentation without performing the action:
ts = C.scene.tool_settings; is_cursor = ts.transform_pivot_point == "CURSOR"; operator(L, "wm.context_set_enum", text="Cursor Active" if is_cursor else "Use Cursor", icon="PIVOT_CURSOR", depress=is_cursor, data_path="scene.tool_settings.transform_pivot_point", value="CURSOR")Keep the label change modest. A stable noun plus a clear state is easier to scan than a button whose identity changes completely.
Prefer the native control when it is enough
If the goal is simply to expose Blender’s enum, a native property control is shorter and carries Blender’s standard behavior:
L.prop(C.scene.tool_settings, "transform_pivot_point", text="Pivot")For one native enum choice:
L.prop_enum(C.scene.tool_settings, "transform_pivot_point", "CURSOR", text="Cursor")Use the state-aware operator button when you need custom action semantics, a deliberate icon, a custom label, or visible pressed-state feedback beyond the native control.
Pitfalls
- A Custom item is redrawn repeatedly. Read state while drawing, and assign scene data only when the operator runs.
depress=changes presentation, not availability. Userow.enabledor a Poll method when the action must be unavailable.- Editor-specific state such as
C.space_data.shadingis valid only in the matching Blender editor. - The button should use the current RNA owner. Old copied paths can stay syntactically valid while pointing at obsolete state.
- Put long workflows in a Macro or a trusted external script and keep the layout expression readable.
This PME 2.1 example uses C, L, and the public wm.context_set_enum operator. It avoids the internal legacy pme.exec convenience operator.
Related
- Choose Command, Property, Menu, Hotkey, or Custom
- Enable an action with a PME Property
- Expose one axis of a vector property
- Give enum buttons explicit labels