4
$\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$
  • $\begingroup$ Enable python tooltips in the preferences, then go to View > Viewpoint > Top and wait a second. $\endgroup$ – brockmann Aug 26 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 at 14:27
  • $\begingroup$ Common question: blender.stackexchange.com/questions/6101/… $\endgroup$ – brockmann Aug 26 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 at 14:44
6
$\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$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.