0
$\begingroup$

I'm new to blender and python. I would like to create a pie menu that lists the "pivot center for rotation/scaling" items (active element, median point, 3d cursor, ...).

I found the very useful "Ui Pie Menu" python template in the text editor, but I don't know what to replace the "pie.operator_enum"'s function arguments with, here is the template code:

import bpy
from bpy.types import Menu

# spawn an edit mode selection pie (run while object is in edit mode to get a valid output)


class VIEW3D_PIE_template(Menu):
    # label is displayed at the center of the pie menu.
    bl_label = "Select Mode"

    def draw(self, context):
        layout = self.layout

        pie = layout.menu_pie()
        # operator_enum will just spread all available options
        # for the type enum of the operator on the pie
        pie.operator_enum("mesh.select_mode", "type")


def register():
    bpy.utils.register_class(VIEW3D_PIE_template)


def unregister():
    bpy.utils.unregister_class(VIEW3D_PIE_template)


if __name__ == "__main__":
    register()

    bpy.ops.wm.call_menu_pie(name="VIEW3D_PIE_template")

I know that I need to replace this line:

pie.operator_enum("mesh.select_mode", "type")

But what with?

I tried this without luck:

pie.operator_enum("bpy.context.space_data.pivot_point")

but it didn't work.

$\endgroup$

1 Answer 1

2
$\begingroup$

Window manager context operators

Just as there is a window manager operator to call a pie menu, there is also a cluster of bpy.ops.wm.context_blah(...) operators, including

bpy.ops.context_pie_enum(data_path="")

which expands the enum property elements in a pie menu. The data_path parameter is the path from context. In this example context.space_data.pivot_point the RNA string path from context is "space_data.pivot_point"

enter image description here

Test script, needs the context of a VIEW3D space. For convenience I prepended a button to the VIEW3D header.

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()
$\endgroup$
0

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .