I tried all 16 combinations, some of them joined the areas but worked only once when I ran the code (not when I called the operator, strangely), but if I drag another screen to try again. It’s not working anymore.
But note that there is quite a bit of wriggle room so you don’t have to be too exact. In your example it could be anywhere along that horizontal line and vertically just has to be close.
Probably the first thing that is going to screw you up is that I don’t think we actually have exactly what you want exposed to python, which would be a simple non-interactive join of two areas. That would be useful.
This thing that you are calling is (I think) just going to initiate an interactive join at a particular position, normally actual cursor position but here you are overriding that with that “cursor” argument. To specify that position you’d need both horizontal and vertical values. You can’t just use widths and heights because the left and top edges are probably not at the screen edges. So X is more like area1.x + (area1.width / 2) and the Y is probably just area1.y. Or you could find the (almost) identical values using the top of area2.
Something like that anyway. I have never tried it from python, although I know some people have. Programmatically starting an interactive process seems a bit goofy though, since it will still require a movement of your mouse to finish it.
I was thinking that if “area_split” allows to non-interactively split the area, then so would “area_join”.
Also there are some examples on the net, but they used to require 4 arguments instead of 2…
There is also this example here, but I can’t replicate it… I’m probably messing up the formula.
I’m not really surprised as that is not what I said to try. Looking at your illustration, with area1 on top and area2 below, this would be a location half-way across horizontally, but on the bottom on area2. Certainly isn’t between them.
# VERTICAL SPLIT FORMULA
bpy.ops.screen.area_join(cursor=(area1.x, area1.y + area1.width))
# HORIZONTAL SPLIT FORMULA
bpy.ops.screen.area_join(cursor=(area1.x, area2.y + area2.height))
Now, a very weird thing is happening…
I have attributed the shortcut ‘F1’ to launch the operator (it works from all editors on the screen).
And then I follow these exact steps in that exact order:
1) I run the script # From the Text Editor nearby
2) I call the operator (F1) # Nothing happens (here I expected the areas to be joined)
3) I re-run the script # The 2 areas get joined without any interaction on my part... Weird!
Hey Ryxx, have you figured this out yet? I was trying your script and I believe I did everything ‘correctly’ since I have been delving pretty deep into this area_join operator, but nothing happens in my case.
I’m using Blender 3.0.0 alpha. I noticed that there is a new operator in this version called bpy.ops.screen.area_close () but it currently gives an error ‘invalid operator call’… Interesting though, maybe someone is working on another way of closing areas.
Actually, I got it to work exactly as you described on 2.93.
Fairly soon I’ll work on getting Python support for the new “Close” operator and some changes to “Join” so it can work better with a passed “Direction” so you can specify which area is remaining and which is meant to close, and should allow you to do the complex joins that are now possible.
Planning on submitting patches in a week or two or so.
Brilliant! I was just thinking of what an ideal add-on would look like if I were to try creating one… I thought it would be cool if the joining had similar functionality to pie menus - with the effortless press and release as you move the mouse in a direction. I made a graphic. I wonder if something like this could be possible…
I haven’t had much to do with Python support so started with the simpler part, doing so for my new “Close” - ⚙ D12307 Python: Allow Area Close via Scripting - then can use anything learned in the review process for “Join” afterward.
Tried this solution but the UI goess bonkers and seems to be stuck. Only when i call the preferences does the window actually refresh or redraw. I tried adding context.area.tag_redraw() but it returns error because i think its trying to redraw the just closed screen area