5
$\begingroup$

I have a set up with a number of orthogonal viewports, and I would like them to jump to whatever is currently selected. I know I can press 'View lock to selected', which moves the viewport along when I move an object, but if I start to work on another object, I have to issue the command again for every viewport.

So far the closest I've come is to go to the properties of each viewport N and under View, select 'Lock to cursor' (which locks the view to the 3d cursor) then ShiftS and 'Cursor to selected', which is reasonably easy. But can I just make it lock to (and zoom to extents of) whichever object I have selected?

$\endgroup$
0

3 Answers 3

3
$\begingroup$

Note that there is a keyboard shortcut for locking the view to the selected object, ShiftNumpad . (Not sure if you knew already or not, but It might make your workflow faster)

Python:

You could use the python api to create a simple script to lock the view to the selected object for all 3D views:

import bpy

for area in bpy.context.screen.areas:
    if area.type == 'VIEW_3D':
        for space in area.spaces:
            if space.type == 'VIEW_3D':
                if space.region_3d.view_perspective == 'ORTHO': # if view is orthographic, do the following:
                    space.lock_object = bpy.context.object # Set the view lock object to the active object

Here is the above code made into an addon based on the addon tutorial in the Blender API reference:

bl_info = {
    "name": "Lock all views to active",
    "category": "3D View",
    "description": "Sets all the 3D views to be locked to the active object",
    "location": "Ctrl+Shift+Space",
}

import bpy


class ViewLockAll(bpy.types.Operator):
    """Lock all views to selected objects"""
    bl_idname = "view3d.lock_all_to_active"
    bl_label = "Lock all views to active object"
    bl_options = {'REGISTER', 'UNDO'}

    def execute(self, context):

        for area in bpy.context.screen.areas:
            if area.type == 'VIEW_3D':
                for space in area.spaces:
                    if space.type == 'VIEW_3D':
                        if space.region_3d.view_perspective == 'ORTHO':
                            space.lock_object = bpy.context.object

        return {'FINISHED'}


addon_keymaps = []


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

    # handle the keymap
    wm = bpy.context.window_manager
    km = wm.keyconfigs.addon.keymaps.new(name='Object Mode', space_type='EMPTY')
    kmi = km.keymap_items.new(ViewLockAll.bl_idname, 'SPACE', 'PRESS', ctrl=True, shift=True)
    addon_keymaps.append((km, kmi))

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

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


if __name__ == "__main__":
    register()

You can install this like any other addon. It will create an operator called ViewLockAll and a keyboard shortcut CtrlShiftSpace for calling it.

$\endgroup$
2
  • $\begingroup$ Very nice! Is there a way to call it automatically when you select another object? And also to not lock the main view, just the orthogonal ones? $\endgroup$
    – David S.
    Nov 17, 2013 at 15:04
  • $\begingroup$ @DavidS. I'm not sure about automatically running it, I thought maybe you cold replace the select operator with an operator which would select then lock the views, but there doesn't seem to be a select operator? Anyway you can make it lock only the orthographic viewports by checking view_perspective first. See my edit. $\endgroup$
    – gandalf3
    Nov 17, 2013 at 18:16
2
$\begingroup$

As far as I'm aware there is no way to do this currently without using some custom Python code.

As I'm not a Python programmer the most I can do for you is tell you the basic logic for that, but that's about it.

You would need to write a script that is called upon object selection, and changes the view lock to the selected object.

$\endgroup$
1
  • 1
    $\begingroup$ Interesting to know that it can at least be done. I am a programmer but I have very limited experience with Python and no experience with Blender's API. $\endgroup$
    – David S.
    Nov 17, 2013 at 0:08
2
$\begingroup$

You could probably experiment using this with what you have tried so far but if I am reading your question correctly, instead of your current workflow you could achieve something similar sans the single step a script would solve by just zooming to the object once you are in that viewport.

Just select the object and press Numpad. (period).

$\endgroup$

You must log in to answer this question.

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