How to fire these simple commands?

Hi Blender coders,

I would like to create some custom pie menus for Transform Orientation and Pivot Point, but it doesn’t make sense yet for me.

One of the command I’m looking for seems to be this one :

bpy.context.scene.tool_settings.transform_pivot_point = 'CURSOR'

So for my pie menu I would write it like this :

	pie.operator("tool_settings.transform_pivot_point", value = 'CURSOR')
	pie.operator("tool_settings.transform_pivot_point", value = 'MEDIAN_POINTS')
	pie.operator("scene.type", value = 'LOCAL')

It doesn’t work. I don’t understand yet the logic behind commands in Blender. I guess it doesn’t work because it triggers a scene or context state and not an operator.

Coming from Modo ( where command creation is really easy but less powerful ultimately ), it’s hard to wrap my head around this and googling for hints haven’t really helped me, neither digging in Blender own pie menus .py files. :grimacing:

How to write the right way this kind of command ?

  • right click on any button on the 3d view header and select ‘Edit Source’
  • open “space_view3d.py” in the text editor
  • search for “pivot_pie” and you’ll find this:
class VIEW3D_MT_pivot_pie(Menu):
    bl_label = "Pivot Point"

    def draw(self, context):
        layout = self.layout
        pie = layout.menu_pie()
        obj = context.active_object
        mode = context.mode

        pie.prop_enum(context.scene.tool_settings, "transform_pivot_point", value='BOUNDING_BOX_CENTER')
        pie.prop_enum(context.scene.tool_settings, "transform_pivot_point", value='CURSOR')
        pie.prop_enum(context.scene.tool_settings, "transform_pivot_point", value='INDIVIDUAL_ORIGINS')
        pie.prop_enum(context.scene.tool_settings, "transform_pivot_point", value='MEDIAN_POINT')
        pie.prop_enum(context.scene.tool_settings, "transform_pivot_point", value='ACTIVE_ELEMENT')
        if (obj is None) or (mode in {'OBJECT', 'POSE', 'WEIGHT_PAINT'}):
            pie.prop(context.scene.tool_settings, "use_transform_pivot_point_align")
1 Like

Nice, big thanks to you !

I tried to get the command for Transform Orientation the same way but the code for the Orientation pie menu isn’t written the same way :

class VIEW3D_MT_orientations_pie(Menu):
    bl_label = "Orientation"

    def draw(self, context):
        layout = self.layout
        pie = layout.menu_pie()
        scene = context.scene

        pie.prop(scene.transform_orientation_slots[0], "type", expand=True)

I’m bad at Python but it seems the command iterates through a list and so the pie buttons are generated automatically from the list elements ?

If so, how one can extract and run a specific command from the original list ? Or do I have to modify this data with another command ?

I tried this one but it doesn’t work :

pie.prop_enum("context.scene.transform_orientation", text="", icon='OBJECT_DATA', value ="NORMAL")

I’m really clueless with theses commands, does anyone have any advice or learning material to get started ?

It’s

pie.prop_enum(context.scene.transform_orientation_slots[0], "type", value='NORMAL')

If you take a look at my first post, you can see that it’s the same logic.

argument 0: path to the property
argument 1: name of the property as string (using quotation marks)
argument 2: the value you want to set

python API:
https://docs.blender.org/api/blender2.8/bpy.types.UILayout.html?highlight=prop_enum#bpy.types.UILayout.prop_enum

I was close but not close enough. Don’t know why I’ve quoted the path.

Thank you again helluvamesh !!
It works …in the script window. I can’t get it to work in the 3D view with a keymap :grimacing:


import bpy
from bpy.types import Menu

class VIEW3D_PIE_ActionCenter(Menu):
    # label is displayed at the center of the pie menu.
    bl_label = "Action Center"
	bl_idname = "p.actioncenter"

    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
        # WEST
        pie.operator("view3d.snap_cursor_to_selected", icon = "SNAP_ON")
        # EAST
        pie.operator("view3d.snap_cursor_to_center",icon = "SNAP_ON")
        # SOUTH
        pie.prop_enum(context.scene.transform_orientation_slots[0], "type", value='GLOBAL')
        # NORTH
        pie.prop_enum(context.scene.tool_settings, "transform_pivot_point", value='MEDIAN_POINT')
        # NW
        pie.prop_enum(context.scene.tool_settings, "transform_pivot_point", value='CURSOR')
        # NE
        pie.prop_enum(context.scene.tool_settings, "transform_pivot_point", value='INDIVIDUAL_ORIGINS')        
        # Sw
        pie.prop_enum(context.scene.transform_orientation_slots[0], "type", value='NORMAL')
        # SE
        pie.prop_enum(context.scene.transform_orientation_slots[0], "type", value='LOCAL')

def register():
    bpy.utils.register_class(VIEW3D_PIE_ActionCenter)
#	bpy.ops.wm.call_menu_pie(name=VIEW3D_PIE_ActionCenter.bl_idname)


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


if __name__ == "__main__":
    register()


I don’t get why it doesn’t work since :

  • I’ve started from the Pie Menu template
  • I use wm.call_menu_pie
  • I call the class VIEW3D_PIE_ActionCenter

Has something changed on this side with 2.8 ?

Check out the addon_add_object.py template to see how to properly write an addon. Then you have to enable it in Header > File > Preferences > Addons. The you can make a shortcut in the 3D View > 3D View (Global) category. And either delete the bl_idname or use that to refer to the menu in your keymap instead of the class name.

Thanks again @helluvamesh, I was finally able to get my custom pie menu.

I didn’t remember that you must have to register a pie as an addon to use it in 2.79, but anyway it works.

Here is the .py file for those who are interested, you have to install manually through the Add-On section in the User Prefs.

pie_actioncenter.py (1.8 KB)