How to switch "context area type" via Pie command? Object/EditNodesUVImage 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:

bpy.ops.object.editmode_toggle()

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


So I tried this but obviously it odes not work

pie.operator("context.area").type='IMAGE_EDITOR'


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: &lt;unknown location&gt;:-1
There are already shortcuts defined to switch areas.

UserPreferences -&gt; Input -&gt; 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.



Note

You can find a listing of all context attributes here