is there a way to detect what view global or local is active via python?
Can I set them directly somehow or at least always come back to global one? In a way where if script is executed view is moved to global no matter what view user is in.
Blender Stack Exchange is a question and answer site for people who use Blender to create 3D graphics, animations, or games. It only takes a minute to sign up.
Sign up to join this communityis there a way to detect what view global or local is active via python?
Can I set them directly somehow or at least always come back to global one? In a way where if script is executed view is moved to global no matter what view user is in.
Here is a trick:
import bpy
is_local_view = sum(bpy.context.space_data.layers[:]) == 0
In "local_view" mode all layers disabled, while in "regular" mode one of them always enabled.
This check is using the context, assuming you are in the 3D view already, you can then exit with localview op;
if context.space_data.local_view:
bpy.ops.view3d.localview()
It can be done this way:
for area in bpy.context.screen.areas:
if area.type == 'VIEW_3D':
space = area.spaces[0]
if space.local_view: #check if using local view
for region in area.regions:
if region.type == 'WINDOW':
override = {'area': area, 'region': region} #override context
bpy.ops.view3d.localview(override) #switch to global view
bpy.ops.render.render(write_still=True, use_viewport=True)
, I still got images containing all objects.
$\endgroup$
Thanks to Юрий Сивальнев, I searched the API a little more. The Object type has a property layers_local_view
. It is an eight member list, all false if the object is not in local view. If you know a particular object you would like to check in the local view space, then you can use this property.
def is_local(ob):
if ob.layers_local_view[0]:
return True
else:
return False