2
$\begingroup$

I have an idea. For example, I have three 3D View areas. And when I change view in the biggest one, in another 2 views direction must change too. For example #2, if I press 1 when the biggest window is active, then in 2 other 3D View windows view direction must change to Top and Right. And if I press 3 in biggest window, directions of view in other windows must change to Top and Front. Now I just have access to all areas by using this code

    bpy.context.window_manager.windows[0].screen.areas

I hope you understand me, sorry for bad english.

$\endgroup$

1 Answer 1

1
$\begingroup$

Register a new operator that changes the views to your liking and bind it to a hotkey.

You can calculate the size of an area by multiplying width * height if that marries up with your idea of area size:

import bpy

class VIEW3D_OT_viewmulti(bpy.types.Operator):
    """Adjust 3D Views based on size (required 3)"""
    bl_idname = "view3d.viewmulti"
    bl_label = "Change multiple views"
    bl_options = {'REGISTER', 'UNDO'}

    def execute(self, context):

        areas = sorted((area for area in context.screen.areas if area.type == 'VIEW_3D'), key=lambda a: a.width * a.height, reverse=True)

        if len(areas) < 3:
            self.report({'ERROR'}, "Not enough 3D Views (< 3)")
            return {'CANCELLED'}

        ctx = context.copy()
        ctx['area'] = areas[0]
        ctx['region'] = areas[0].regions[-1]
        bpy.ops.view3d.viewnumpad(ctx, 'INVOKE_DEFAULT', type='FRONT')

        ctx['area'] = areas[1]
        ctx['region'] = areas[1].regions[-1]
        bpy.ops.view3d.viewnumpad(ctx, 'INVOKE_DEFAULT', type='TOP')

        ctx['area'] = areas[2]
        ctx['region'] = areas[2].regions[-1]
        bpy.ops.view3d.viewnumpad(ctx, 'INVOKE_DEFAULT', type='RIGHT')

        return {'FINISHED'}


# store keymaps here to access after registration
addon_keymaps = []

def register():

    bpy.utils.register_module(__name__)

    # handle the keymap
    wm = bpy.context.window_manager
    km = wm.keyconfigs.addon.keymaps.new(name='3D View Generic', space_type='VIEW_3D')

    kmi = km.keymap_items.new(VIEW3D_OT_viewmulti.bl_idname, 'SPACE', 'PRESS', ctrl=True, shift=True)

    addon_keymaps.append((km, kmi))


def unregister():

    bpy.utils.unregister_module(__name__)

    # handle the keymap
    for km, kmi in addon_keymaps:
        km.keymap_items.remove(kmi)
    addon_keymaps.clear()

if __name__ == '__main__':
    register()

Hotkey in above example code is CtrlShiftSpace.

$\endgroup$

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .