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.