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


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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.