0

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()
George
  • 33
  • 3
  • You can access and modify the view_matrix directly.
    https://blender.stackexchange.com/questions/265693/how-can-you-find-the-position-and-rotation-direction-of-the-viewport/265709#265709
    – X Y Apr 12 '23 at 16:55

1 Answers1

1

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

George
  • 33
  • 3