I would like to create an operator that would trigger a pie menu containing the "pivot center modes" in it (median point, individual origins, 3d cursor, ...).
Now I could get started with the code below (from that topic: bpy: how do I list the "pivot center for rotation/scaling" items?
import bpy
def piebut(self, context):
layout = self.layout
op = layout.operator("wm.context_pie_enum")
op.data_path = "space_data.pivot_point"
def register():
bpy.types.VIEW3D_HT_header.prepend(piebut)
def unregister():
bpy.types.VIEW3D_HT_header.remove(piebut)
if __name__ == "__main__":
register()
The code above will add a button to the 3dView header, and when you press that button, it will display a pie menu with the "pivot center modes" items in it.
However, I would like to convert this to an operator, so that I can ultimately press a shortcut key to open the pie menu directly (without having to click a button).
Now I've tried this without luck:
import bpy
class LING_OT_PIEMENU_PivotCenterModes(bpy.types.Operator):
"""A pie menu to select the pivot center for rotation and scaling"""
bl_idname = "view3d.ling_piemenu_pivot_center_modes"
bl_label = "Pivot center for rotation/scaling"
def execute(self, context):
bpy.ops.wm.context_pie_enum("space_data.pivot_point" )
return {'FINISHED'}
# just for quick testing inside the blend file
bpy.utils.register_class(LING_OT_PIEMENU_PivotCenterModes)
I've changed those lines:
layout = self.layout
op = layout.operator("wm.context_pie_enum")
to this line:
bpy.ops.wm.context_pie_enum("space_data.pivot_point" )
because layout = self.layout was returning a None type, so I thought the layout property was not available from the operator class, and so I tried to call the context_pie_enum method in a different manner, but now I've got this error:
TypeError: Calling operator "bpy.ops.wm.context_pie_enum" error, expected a string enum in ('INVOKE_DEFAULT', 'INVOKE_REGION_WIN', 'INVOKE_REGION_CHANNELS', 'INVOKE_REGION_PREVIEW', 'INVOKE_AREA', 'INVOKE_SCREEN', 'EXEC_DEFAULT', 'EXEC_REGION_WIN', 'EXEC_REGION_CHANNELS', 'EXEC_REGION_PREVIEW', 'EXEC_AREA', 'EXEC_SCREEN')