0
$\begingroup$

What is the python command to check if current view is in orthographic or perspective mode?

$\endgroup$
1
  • $\begingroup$ Why the downvote? $\endgroup$ – Pullup Jun 3 '20 at 19:59
3
$\begingroup$

Region3D.view_perspective.

Get the space data of the 3D view area. A screen is split up into areas. The space associated with area is the active space. The spaces 3d region has the view settings.

>>> for i, a in enumerate(C.screen.areas):
...     i, a.type
...     
(0, 'PROPERTIES')
(1, 'CONSOLE')
(2, 'VIEW_3D')
(3, 'TEXT_EDITOR')

>>> space = C.screen.areas[2].spaces.active

If we are sure we are in a 3d view (a panel there, an operator that polls there) then instead use

space = context.space_data

the property to change is view_perspective, in example below I am in perspective view

>>> space.region_3d.view_perspective
'PERSP'

Tip A quick way to find the options available is crunch in something wrong.

>>> space.region_3d.view_perspective = 'FOO'
Traceback (most recent call last):
  File "<blender_console>", line 1, in <module>
TypeError: bpy_struct: item.attr = val: enum "FOO" not found in ('PERSP', 'ORTHO', 'CAMERA')

Check if in ortho view. Could also check if in camera view, is camera ortho

>>> ortho_view = space.region_3d.view_perspective == 'ORTHO'

or perhaps (needs testing)

>>> ortho_view = not space.region_3d.is_perspective

Set to ortho

>>> space.region_3d.view_perspective = 'ORTHO'
$\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.