In a Pie menu instead of switching just edit/object mode I would also like to swap out the content of the display like from 3D view switch to node editor for the selected object. But I have a hard time figuring out how to write this.

I went to the API page to see if many I can get some clues from there. https://www.blender.org/api/blender_python_api_2_76_2/bpy.context.html?highlight=context.area#bpy.context.area

If I switch the modes the console reads this out:

bpy.context.area.type = 'IMAGE_EDITOR'
bpy.context.area.type = 'NODE_EDITOR'
bpy.context.area.type = 'VIEW_3D'

To define a edit/object mode switch I 3D view I know you can do it this way:


pie.operator("object.editmode_toggle", text="Edit/Object", icon='OBJECT_DATAMODE')

So I tried this but obviously it odes not work


With the following error message:

Traceback (most recent call last):
  File "\Modeling Toolbox Pie Beta.py", line 654, in draw

AttributeError: 'NoneType' object has no attribute 'type'

location: <unknown location>:-1

Wazou wrote a good viewport/editor switch pie a while back and I've been modifying it lately. You can find it on github in addons_extern. I don't completely understand it, but I believe it's close to what you're asking for. You could probably borrow some parts of the code for your own pie.

  • $\begingroup$ I studied it but to my knowledge it only switches between edit/object/sculpt mode and not swaping out the 3D view with the node or image editor module. $\endgroup$ Jan 17 '16 at 22:56
  • $\begingroup$ We're looking at different scripts, because viewport_pie_menu.py allows you to change editors in a window. Press shift-space over any editor other than the console and it gives you options to switch between editors. Up is 3D view, left is a submenu of image editors, etc. $\endgroup$
    – Italic_
    Jan 17 '16 at 23:58
  • $\begingroup$ OPS - same name different thing. Thank you for this! The example is perfect to learn from! $\endgroup$ Jan 18 '16 at 0:53

There are already shortcuts defined to switch areas.

UserPreferences -> Input -> Window

If you browse these shortcuts you will find Context Set Enum, which uses the generic wm.context_set_enum operator. The keys are SHIFTF1-F12

So you can copy the arguments:

op_props = pie.operator("wm.context_enum_set")
op_props.data_path = "area.type"
op_props.value = "VIEW_3D"

See Area.type for the available options

Further you might also try wm.context_pie_enum to automatically layout all enum items in a pie menu.

Just define a shortcut and type area.type in the data_path field.


You can find a listing of all context attributes here

  • $\begingroup$ Tested context_pie_enum and it seems to be buggy :/ - multiple areas are assigned to the same direction. $\endgroup$ Jan 19 '16 at 15:23

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.