I can change the window type to "node editor" with

bpy.context.window_manager.windows[0].screen.areas[0].type = 'NODE_EDITOR'

but how to set it type to "compositing"?

enter image description here


If you mouse over the property you will see it is the SpaceNodeEditor.tree_type property you want to set. The screen is split into areas, these areas have regions, toolbar header etc, and spaces. I've put a print statement in to show the spaces for the area. To get the space associated with an area use area.spaces.active or context.space_data (after changing the context.area.type)

import bpy
from bpy import context

area = context.area

area.type = 'NODE_EDITOR'
# the context area is now a node editor
# the space has the tree_type enum

for sp in area.spaces:
    print(sp, sp.type, "has tree_treetype", hasattr(sp, "tree_type"))

space = context.space_data
# or better still
space = area.spaces.active
# set to compositing    
space.tree_type = 'CompositorNodeTree'

To find space.tree_type = 'CompositorNodeTree' run code above with space.tree_type = 'Blah' which gives the options in the error message.

TypeError: bpy_struct: item.attr = val: 
enum "Blah" not found in 
('ShaderNodeTree', 'CompositorNodeTree', 'TextureNodeTree')
  • $\begingroup$ Thanks, it works for me as: bpy.context.window_manager.windows[0].screen.areas[0].spaces.active.tree_type = 'CompositorNodeTree' $\endgroup$ – Korchiy Dec 10 '16 at 13:51

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.