A set of operators is provided in Blender for manipulating with the location of its interface windows.
To split the current window (using the current context) into two in a specified ratio, we need to execute the following operator:
1 |
bpy.ops.screen.area_split(direction='VERTICAL', factor=0.5) |
With:
- direction – set the splitting direction (‘HORIZONTAL’ or ‘VERTICAL’)
- factor – percentage ratio of splitting windows
A new window (new area) is appended to the end of the bpy.context.screen.areas list and can be obtained through the:
1 |
new_area = bpy.context.screen.areas[-1] |
To join two windows into one, we need to execute the following operator:
1 |
bpy.ops.screen.area_join(cursor=(x1, y1)) |
With:
- x1, y1 – left top corner coordinates of the joined window (area)
Area corner coordinates we can get from the area “x” and “y” properties:
1 2 3 4 |
bpy.context.screen.areas[-1].x # 1259 bpy.context.screen.areas[-1].y + bpy.context.screen.areas[-1].width # 912 |
Does the joining of the areas here work for the active area (the one where the cursor is currently, or which has been clicked most recently)? Or does it just work for the area that was created last?
I’d like to be able to join the area where the cursor is hovering with another one…
Joining depends only on the coordinates you send to the operator. Get the coordinates of your active area and use them in the operator.
Do you have any tips on how to find coordinates of the active area? I believe the bpy.context.screen.areas[–1] refers to the area that was created last, but not necessarily the active area. Thanks.
Also, could you confirm whether you made a typo in your article? It says x1, y1 are left top corner coordinates. But if I understand correctly, x1 is top left and y1 is actually bottom right?
Actually, I have tried seemingly every possible option but in my case screen area join just doesn’t do anything. I also attempted the script that was shared in this forum: https://devtalk.blender.org/t/join-two-areas-by-python-area-join-what-arguments-blender-2-80/18165/7
Sometimes areas are not redrawing automatically after joining with the API. I think that this is the Blender issue. After joining try to move manually the border between other areas to call the screen refreshing.
should be:bpy.ops.screen.area_join(cursor=(new_area.x+new_area.width+2, new_area.y+2))
And blender will definitely not redraw, you need to find another redraw function.
Yes, a screen redrew is needed.
x and y are just coordinates. The point on your screen, like you join areas manually. You move the mouse to the angle of the area press and drug. The coordinates of the point where you press you store to the operator to do this with the api.
You can get the active area from
bpy.context.area
Hello Nikita 🙂
Could you give an example of another way to connect two windows. For example, by the type of window. For example, VIEW_3D merges with INFO. It’s hard to find which window has what number is assigned.
Hello!
You can get all the areas with their coordinates through the bpy.context.screen.areas.
For example execute in the Python console the following:
[(area, area.type, area.x, area.y) for area in bpy.context.screen.areas]
the result should be something like this:
[(bpy.data.screens[‘Layout’]…Area, ‘OUTLINER’, 1577, 24), (bpy.data.screens[‘Layout’]…Area, ‘VIEW_3D’, 717, 24), (bpy.data.screens[‘Layout’]…Area, ‘NODE_EDITOR’, 0, 374), (bpy.data.screens[‘Layout’]…Area, ‘CONSOLE’, 0, 24)]
Ok, Thank You for Your reply. This method is ok, but sometimes different user, have different resolution of screen . And You must know how big is area…
Tries to create a scrypt that automatically join area to recognize type.
Greets and thanks for help 🙂
Every area has the “width” and “height” attributes to get its size.