1
$\begingroup$

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

$\endgroup$

1 Answer 1

1
$\begingroup$

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
$\endgroup$

You must log in to answer this question.

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