0
$\begingroup$

a Blender python beginner here. I'm sorry if this is a trivial question but I couldn't find an answer for this anywhere.

I am making a script that checks if selected object is in local view and if it is, it will toggle it back to global view. Something like this:

if bpy.context.active_object.local_view_get() == True:
            bpy.ops.view3d.localview

However I don't really understand what the viewport parameter should be, I tried to find answer but I guess my understanding of Blender classes is still very poor.

$\endgroup$
3

1 Answer 1

0
$\begingroup$

You can check whether certain viewport is in local_view by accessing its local_view property which returns either true/false. First you need to specify the viewport:

for area in bpy.context.screen.areas:
    if area.type == 'VIEW_3D':
       view_3d = area.spaces.active
    

Then you can access its local_view property:

if view_3d.local_view:
   print("Local view active")
else:
   print("Local view not active")

Like this it's gonna return the state whenever you run the script. To do this automaticaly whenever the viewport changes you're gonna have to create a custom handler

$\endgroup$
2
  • $\begingroup$ Thank you, this seems to work! $\endgroup$ Apr 14, 2023 at 14:17
  • $\begingroup$ to elaborate your question, To check what objects are visible you would loop through all objects in the scene and do: obj.local_view_get(view3d.local_view) for each. That is according to the docs. Unfortunatelly there seems to be a bug and it always returns False no matter what. My workaround would be to select all objects in the local view which will give you the list you want. $\endgroup$ Apr 14, 2023 at 14:42

You must log in to answer this question.

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