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?
Blender Stack Exchange is a question and answer site for people who use Blender to create 3D graphics, animations, or games. It only takes a minute to sign up.
Sign up to join this communityYes, 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")
type is only used for documentation. Try bpy.context.region_data.is_perspective
$\endgroup$
space_data. Will update answer.
$\endgroup$