Skip to content

Instantly share code, notes, and snippets.

@zeffii
Last active June 30, 2016 08:37
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save zeffii/4d28dac045c58bb6f124efef63db8ed8 to your computer and use it in GitHub Desktop.
Save zeffii/4d28dac045c58bb6f124efef63db8ed8 to your computer and use it in GitHub Desktop.
import bpy
def get_largest_area():
window_reference = None
surface_area = 0
ctx = None
for window in bpy.context.window_manager.windows:
for area in window.screen.areas:
w, h = area.width, area.height
surface = w * h
if surface > surface_area:
surface_area = surface
window_reference = area
override = bpy.context.copy()
override['area'] = area
return window_reference, surface_area, override
class OpenNodeEditor(bpy.types.Operator):
"""Open the node editor"""
bl_idname = "scene.open_node_editor"
bl_label = "Open Node Editor"
bl_options = {'REGISTER', 'UNDO'}
def execute(self, context):
area, size, ctx = get_largest_area()
bpy.ops.screen.area_split(ctx, direction='HORIZONTAL',factor=0.5)
bpy.ops.wm.context_set_string(ctx, data_path="area.type", value="NODE_EDITOR")
return {'FINISHED'}
class LayoutDemoPanel(bpy.types.Panel):
"""Creates a Panel in the scene context of the properties editor"""
bl_label = "Layout Demo"
bl_idname = "SCENE_PT_layout"
bl_space_type = 'PROPERTIES'
bl_region_type = 'WINDOW'
bl_context = "scene"
def draw(self, context):
layout = self.layout
scene = context.scene
row = layout.row()
row.operator("scene.open_node_editor")
def register():
bpy.utils.register_class(OpenNodeEditor)
bpy.utils.register_class(LayoutDemoPanel)
def unregister():
bpy.utils.unregister_class(LayoutDemoPanel)
bpy.utils.unregister_class(OpenNodeEditor)
if __name__ == "__main__":
register()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment