0
$\begingroup$

I have tried to write a script to set the 3d view to the top view and also turn it in into an orthogonal projection

The closest I have got to the objective is based on this code found in this thread which can set the view to Top, however, it won't change the projection to an orthogonal one.

import bpy
for area in bpy.context.screen.areas:
    if area.type == 'VIEW_3D':
        override = bpy.context.copy()
        override['area'] = area
        bpy.ops.view3d.view_axis(override, type='TOP')
        break

I have found that the following code is listed as the operation that flips perspective into ortogonal view, however I have been unable to implement it without raising errors.

bpy.ops.view3d.view_persportho()
$\endgroup$
1

1 Answer 1

2
$\begingroup$

In this updated solution the view is toggled to orthogonal only if the view is already set to perspective projection.

import bpy

for area in bpy.context.screen.areas:
    if area.type == "VIEW_3D":
        override = bpy.context.copy()
        override["area"] = area
        bpy.ops.view3d.view_axis(override, type='TOP', align_active=False) 
        if  area.spaces.active.region_3d.is_perspective:
            bpy.ops.view3d.view_persportho(override)
        else:
            pass
$\endgroup$
1
  • 1
    $\begingroup$ Note you don't need else: pass here $\endgroup$
    – Gorgious
    Commented Apr 13, 2023 at 17:10

You must log in to answer this question.

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