From the Blender UI there is the option of "Lock to Object" of the Viewport that can be seen in the following image. I wanted to ask how is it possible to enable this option via Python?
1 Answer
$\begingroup$
$\endgroup$
Property of the 3D view space
Similarly to Change tile grid shape and similarly to the answer it was similar to.
Mousing over the property in UI (with developer extras enabled) shows the proprerty as
SpaceView3D.lock_object
Python console, lock 3d viewport area of screen to context object.
>>> for i, a in enumerate(C.screen.areas):
... i, a.type
...
(0, 'PROPERTIES')
(1, 'CONSOLE')
(2, 'OUTLINER')
(3, 'VIEW_3D')
>>> space = C.screen.areas[3].spaces.active
>>> space.lock_object = C.object
>>> C.object
bpy.data.objects['Cube']
>>> space.lock_object
bpy.data.objects['Cube']
>>> type(space)
<class 'bpy.types.SpaceView3D'>
set to None
to remove
space.lock_object = None
For scripts run in the context of the 3d view
space = context.space_data