1
$\begingroup$

View > Perspective/Orthographic (Numpad 5) allows you to toggle between them. I'd like to specify Ortho without toggling, using python.

Here is what I have so far:

def execute(self, context):
    # Switch to orthographic view
    bpy.ops.view3d.view_axis(type='RIGHT')
    bpy.ops.view3d.view_perspective(type='ORTHO')

Which doesn't entirely work. I was checking out this thread, and I'm unable to get the recommendation for setting to Ortho to work either:

space.region_3d.view_perspective = 'ORTHO'

I get a space needs to be defined error, but I don't know if that's exactly what I need anyways. Any thoughts?

$\endgroup$

1 Answer 1

1
$\begingroup$

This worked for me:

import bpy

C = bpy.context

print ("started")

for i, a in enumerate(C.screen.areas):
    print(a.type)
    if a.type == "VIEW_3D":
       
        space = a.spaces.active
        space.region_3d.view_perspective = 'ORTHO'
        print("set ortho")
$\endgroup$
5
  • $\begingroup$ Thank you. How is this being placed, is it inside the class but outside of any functions? It seems to only want to break the pie menu when I try on my end. $\endgroup$
    – Increality
    Commented Nov 24, 2021 at 19:14
  • 1
    $\begingroup$ I just run that script in my text editor - can u verify that this works in your Texteditor? $\endgroup$
    – Chris
    Commented Nov 24, 2021 at 19:24
  • $\begingroup$ It does work running on it's own in the text editor, yes. $\endgroup$
    – Increality
    Commented Nov 24, 2021 at 20:39
  • 1
    $\begingroup$ And from where, or how do you want to trigger this? $\endgroup$
    – Chris
    Commented Nov 24, 2021 at 21:22
  • $\begingroup$ I'm sorry for the late reply, thank you for the response. I'm wanting to trigger this via a button on a pie menu. $\endgroup$
    – Increality
    Commented Dec 5, 2021 at 19:47

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .