2
$\begingroup$

I'm talking about the so-called User Local View, which you can enter by selecting an object and pressing "Numpad /".

I can detect an active "User Perspective":

for area in bpy.context.screen.areas:
   if area.type == 'VIEW_3D':
      if area.spaces.active.local_view is not None:
          print("I'm in a user perspective")

That local view causes some quirks with several Python operations. Is there a way to store the current local view, leave it and re-enter it upon finish?

$\endgroup$
2
$\begingroup$

Check the menu in the 3D view, and right-click the "View Global/Local" menu item. You can then choose "Copy Python Command". It'll give you bpy.ops.view3d.localview(), which is the operator that is executed when you click on that menu item.

Note that it does require a context of a 3D view, so if you try to execute that command as-is in the Python console, it'll refuse (your Python console doesn't have Global/Local view). However, if you execute it as part of your own operator running in a 3D view, it'll be fine. In that case you can also simply use context.area.spaces.active.local_view instead of iterating over all areas in the current screen.

$\endgroup$

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.