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.
Blender Stack Exchange is a question and answer site for people who use Blender to create 3D graphics, animations, or games. It only takes a minute to sign up.Sign up to join this community
bpy.ops.mesh.primitive_*() operators need to be run in a proper context (3D View) in order to use
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) break
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.