0

I would like to change the 3d viewport to orthogonal from a python script. From the key mapping I found this command "view3d.view_persportho". I always find it tricky when I have to mess with the context (Which I think is nescesary). Anyway, I tried this:

for area in bpy.context.window.screen.areas:
        if area.type == 'VIEW_3D':
            for region in area.regions:
                if region.type == 'WINDOW':
                    override = bpy.context.copy()
                    override['area'] = area
                    override['region'] = region
                    override['scene'] = bpy.context.scene                      
                    bpy.ops.wm.setup_ui(override) 
                    # Maybe I can set perspective here somehow?

class MYOP_setup_ui(bpy.types.Operator): bl_idname = "wm.setup_ui" bl_label = "Setup UI" def execute(self, context): context.space_data.show_region_ui = True # This opens the sidebar panels correctly # I know that I can't pass arguments to operators like in the next line. # bpy.ops.view3d.view_persportho('ORTHO') # 'PERSP', 'CAMERA'
return {'FINISHED'}

I found these, which is pretty much what I want, but I can't get it to work. Maybe pre 2.8?

View3D operations problem

https://blenderartists.org/t/determine-whether-or-not-you-are-in-perspective-or-orthographic-view/617907

DrDress
  • 563
  • 4
  • 19
  • Does this answer your question https://blender.stackexchange.com/questions/181110/what-is-the-python-command-to-check-if-current-view-is-in-orthographic-or-perspe – batFINGER Jan 11 '21 at 14:33
  • Yes thanks! context.space_data.region_3d.view_perspective = 'ORTHO' – DrDress Jan 11 '21 at 14:56

0 Answers0