What is the python command to check if current view is in orthographic or perspective mode?
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.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'