I'm not sure how to correctly specify what is written in the blender API documentation. I'm coding:
bpy.ops.object.align( align_mode='OPT_4' )
but get the console error message:
TypeError: Converting py args to operator properties: : keyword "align_mode" unrecognized
The API documentation explains the "align_mode":
bpy.ops.object.align(bb_quality=True, align_mode='OPT_2', relative_to='OPT_4', align_axis={})
Align objects
Parameters
bb_quality (boolean, (optional)) – High Quality, Enables high quality calculation of the bounding box for perfect results on complex shape meshes with rotation/scale (Slow)
align_mode (enum in ['OPT_1', 'OPT_2', 'OPT_3'], (optional)) – Align Mode, Side of object to use for alignment
relative_to (enum in ['OPT_1', 'OPT_2', 'OPT_3', 'OPT_4'], (optional)) –
Relative To, Reference location to align to
OPT_1 Scene Origin, Use the scene origin as the position for the selected objects to align to.
OPT_2 3D Cursor, Use the 3D cursor as the position for the selected objects to align to.
OPT_3 Selection, Use the selected objects as the position for the selected objects to align to.
OPT_4 Active, Use the active object as the position for the selected objects to align to.
align_axis (enum set in {'X', 'Y', 'Z'}, (optional)) – Align, Align to axis
My script (for context):
import bpy
replace imported Mesh Text (selected) with real (editable) Text aligned to old that gets deleted
oldObjects = bpy.context.selected_objects
bpy.ops.object.select_all( action='DESELECT' ) # Deselect all objects
for oldObj in oldObjects:
bpy.ops.object.select_all( action='DESELECT' ) # Deselect all objects
bpy.ops.object.text_add(enter_editmode=False, align='WORLD', location=oldObj.location, scale=(1, 1, 1))
# Delete last 4 letters from template "Text" to leave a single Letter "T"
bpy.ops.object.editmode_toggle()
bpy.ops.font.delete(type='PREVIOUS_OR_SELECTION')
bpy.ops.font.delete(type='PREVIOUS_OR_SELECTION')
bpy.ops.font.delete(type='PREVIOUS_OR_SELECTION')
bpy.ops.object.editmode_toggle()
# align new letter to old mesh
print( oldObj.name + str( oldObj.location ) )
oldObj.select_set(True)
bpy.ops.object.align( align_mode='OPT_4' )
# delete oldObj
bpy.ops.object.select_all( action='DESELECT' ) # Deselect all objects
oldObj.select_set(True)
bpy.ops.object.delete()
and yes I know I could replace the align() with:
bpy.ops.object.text_add(enter_editmode=False, align='WORLD', location=oldObj.location, rotation=oldObj.rotation_euler )
but I want to understand better how understand blender API documentation.
keyword "bb_quality" unrecognized, or whatever keyword I use first! I am trying to understand why I cannot seem to understand the documentation in general in these cases, and it is slowing down my ability to learn the bpy python methods. I am using v2.91 – james_t Mar 22 '21 at 21:12bpy.ops.object.align(and ... how ugly that I can only do this in the console, and not in the editor, although there is a (non-functional) auto-complete under the Edit menu item
– james_t Mar 22 '21 at 22:16align() bpy.ops.object.align() Align Selected To Active
– james_t Mar 23 '21 at 16:45