I was trying to a add a plane primitive using Blender Python and aligning it to the viewport.

I already tried setting align_view = True when adding it via Python, but it doesn't change the rotation at all.


bpy.ops.mesh.primitive_*() operators need to be run in a proper context (3D View) in order to use align_view.

Either run an operator via Spacebar menu, or use an override:

import bpy

for area in bpy.context.screen.areas:
    if area.type == 'VIEW_3D':
        for region in area.regions:
            if region.type == 'WINDOW':
                ctx = bpy.context.copy()
                ctx['area'] = area
                ctx['region'] = region
                bpy.ops.mesh.primitive_plane_add(ctx, view_align=True)

Note that there seems to be a bug, the plane appears to be in Edit mode, but the UI reports Object Mode, and the face may be missing.


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.