Is there a way to make an operator know if the context viewport is in ortho or perspective mode?

I would like my custom operator to have 2 behaviours :

• Case 1: Viewport is in perspective mode, do function 1.
• Case 2: Viewport is in orthogonal mode, do function 2.

How can I get that information with the Python API?

Yes, you can check is_perspective.

You can get the perspective of the current context (provided the current context is a 3D view) with bpy.context.space_data.region_3d.is_perspective.

For example, running this in the text editor will print Perspective or Ortho to the terminal for each 3D view.

import bpy

for area in bpy.context.screen.areas:
if area.type == 'VIEW_3D':
for space in area.spaces:
if space.type == 'VIEW_3D':
if space.region_3d.is_perspective:
print("Perspective")
else:
print("Ortho")

• The link speaks about a type. I can't see how to get that info in context. I mean a full path like bpy.context. ... .RegionView3D.is_perspective Mar 7 '14 at 8:49
• @matali type is only used for documentation. Try bpy.context.region_data.is_perspective
– gandalf3
Mar 7 '14 at 8:52
• gives me eror : object has no item "is_perspective" Mar 7 '14 at 8:55
• @matali Oops, I meant space_data. Will update answer.
– gandalf3
Mar 7 '14 at 9:11
• problem is I need the state of the view where the operator is called, not for every view. So I really need a full path that gives me the context view perspective/ortho state. Mar 7 '14 at 13:15