What is the python command to check if current view is in orthographic or perspective mode?
-
$\begingroup$ Why the downvote? $\endgroup$– PullupJun 3, 2020 at 19:59
-
$\begingroup$ No effort... @Pullup $\endgroup$– brockmannAug 26, 2021 at 15:23
-
$\begingroup$ @Pullup People playing as God ? judging other people by their standard. $\endgroup$– andioAug 31, 2021 at 2:42
1 Answer
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'