1
$\begingroup$

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?

$\endgroup$
4
$\begingroup$

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")
| improve this answer | |
$\endgroup$
  • $\begingroup$ 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 $\endgroup$ – matali Mar 7 '14 at 8:49
  • $\begingroup$ @matali type is only used for documentation. Try bpy.context.region_data.is_perspective $\endgroup$ – gandalf3 Mar 7 '14 at 8:52
  • $\begingroup$ gives me eror : object has no item "is_perspective" $\endgroup$ – matali Mar 7 '14 at 8:55
  • $\begingroup$ @matali Oops, I meant space_data. Will update answer. $\endgroup$ – gandalf3 Mar 7 '14 at 9:11
  • $\begingroup$ 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. $\endgroup$ – matali Mar 7 '14 at 13:15

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.