6
$\begingroup$

Is there a python function that sets ortho view such that X and Y axes are visible - the equivalent of numpad 7?

Thanks in advance!

$\endgroup$
4
  • $\begingroup$ Enable python tooltips in the preferences, then go to View > Viewpoint > Top and wait a second. $\endgroup$
    – brockmann
    Aug 26, 2019 at 14:19
  • $\begingroup$ Thanks; when I tried the code it threw this error: RuntimeError: Operator bpy.ops.view3d.view_axis.poll() failed, context is incorrect $\endgroup$
    – vndep
    Aug 26, 2019 at 14:27
  • $\begingroup$ Common question: blender.stackexchange.com/questions/6101/… $\endgroup$
    – brockmann
    Aug 26, 2019 at 14:28
  • $\begingroup$ Why wouldn't this work: for area in bpy.context.screen.areas: if area.type=='VIEW_3D': bpy.ops.view3d.view_axis(type='TOP') $\endgroup$
    – vndep
    Aug 26, 2019 at 14:44

1 Answer 1

11
$\begingroup$

You can override the context when calling view_axis() operator:

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
$\endgroup$

You must log in to answer this question.

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