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?

enter image description here


1 Answer 1


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


Python console, lock 3d viewport area of screen to context object.

>>> for i, a in  enumerate(C.screen.areas):
...     i, a.type
(1, 'CONSOLE')
(3, 'VIEW_3D')

>>> space = C.screen.areas[3].spaces.active

>>> space.lock_object = C.object
>>> C.object

>>> space.lock_object

>>> 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

You must log in to answer this question.

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