Wazou's Questions about 2.8!

Hey guys, instead of making X threads, I will post my questions here.

Do you know how to have this button in a pie menu or even normal menu?

image

The python code is

bpy.ops.screen.area_split(cursor=(3175, 766))

We can add them to the quick menu, but same, I cannot find the proper code to do exactly the same.

Thx for your help :wink:

See if this works.

layout = self.layout

pie = layout.menu_pie()

pie.operator_context = 'EXEC_DEFAULT'
SCREEN_SPLIT = pie.operator("screen.area_split", text="Split Area")
SCREEN_SPLIT.cursor=(3175, 766)

I tried something like that, but it only cut the view in half.
It’s like using directly

bpy.ops.screen.area_split(direction=‘HORIZONTAL’)

You want it to give the line to choose the split location? I got ya. Looks like it acts the same way in 2.79.

yep, like that, nly one button ^^

Many operators use EXEC_DEFAULT which will execute their parameters.
You can use INVOKE_DEFAULT to make any operator invoke its modal method if it has one:

bpy.ops.screen.area_split('INVOKE_DEFAULT', direction='HORIZONTAL')

If you want an intelligent split that invokes the correct direction (vertical or horizontal), you can wrap it into a modal operator using mouse x,y threshold.

Edit:

And for menu:

layout.operator_context = "INVOKE_REGION_WIN"
op = layout.operator("screen.area_split", text="Split Y")
op.direction = 'VERTICAL'
op = layout.operator("screen.area_split", text="Split X")
op.direction = 'HORIZONTAL'

Yes, but I want the default behavior to chose the axis in the modal.
I already use the vertical and horizontal settings right now.

split

You can still choose axis using MMB during modal? The only difference between this operator invoked from a menu and the action zone, is that action zones will always invoke the perpendicular direction.

Or do you want it to choose split direction based on region dimensions?

I want to call the default tool that gives you the line and the choice with MMB to split horizontal or vertical.

The first code I posted does that! :stuck_out_tongue: The direction is only specified as a starting direction. You can still change it using MMB.

area_split

import bpy

class AreaSplitMenu(bpy.types.Menu):
    bl_label = "Area Split"
    bl_idname = "WM_MT_area_split"

    def draw(self, context):
        layout = self.layout
        w = context.region.width
        h = context.region.height
        dir = 'HORIZONTAL' if h > w else 'VERTICAL'

        layout.operator_context = "INVOKE_REGION_WIN"
        op = layout.operator("screen.area_split", text="Split")
        op.direction = dir
    
def draw_item(self, context):
    layout = self.layout
    layout.menu(AreaSplitMenu.bl_idname)

def register():
    bpy.utils.register_class(AreaSplitMenu)

def unregister():
    bpy.utils.unregister_class(AreaSplitMenu)

if __name__ == "__main__":
    register()

    bpy.ops.wm.call_menu(name=AreaSplitMenu.bl_idname)

Indeed, my bad, this is perfect, thank you :wink:

What part of that code allows the mouse to work? Is it the operator_context? I tested every context option and never could get it to work. Although, I was doing pie menu.

It was for that pie menu I’m making.

1 Like

By the way, how do you join your views?

Yeah.

For operators in menus, setting operator_context = *** is exactly the same as adding execution context in bpy.ops.something('***', kwargs). The difference is that operator_context is set for all consecutively placed operators until changed to something else. By default, operators in menus have an implied 'EXEC_REGION_WIN' which always executes an operator with default settings, but this can be overridden.

I’m using a tweaked version of command_area_join.py from roaoao’s example script included in PME. The old version doesn’t work in 2.8 because Blender introduced exceptions with top and status bar.

ok, thank you.

1 Like

the gif you show is not the result of the code you show. you give width and height of the region, so this is linked to the shape of the window, not the position of the mouse inside. but ok for the invoke…maybe I give the exact way to do it later