I have one object selected, and another object is active. What is the python code for Object>Transform>Align Selected to Active? (requires the addon Object: Align Tools that ships with Blender.)

Also is there a way to force the python Consol to echo all commands?

Any help greatfully received.

  • $\begingroup$ Did not understand, please explain. $\endgroup$
    – Muzammil
    Sep 17, 2022 at 10:54
  • $\begingroup$ There is no menu entry Object > Transform > Align Selected to Active, is it? There is Cltr+S (Snap) > Selection to Active. The console echos all commands by default => bpy.ops.view3d.snap_selected_to_active() $\endgroup$
    – Blunder
    Sep 17, 2022 at 11:01
  • $\begingroup$ In object mode under the object menu, then the transform menu the option at the bottom is Align Selected to Active. (You may need to have the objects align addon active, I don't know.) When you click this option nothing gets output from the python consol. $\endgroup$
    – MattL
    Sep 17, 2022 at 12:27
  • $\begingroup$ I get this error Operator bpy.ops.view3d.snap_selected_to_active.poll() failed, context is incorrect When I force the context to be 'VIEW_3D' in matches the location ut not the rotation. When I use the menu option it matches both location and rotation $\endgroup$
    – MattL
    Sep 17, 2022 at 12:37
  • $\begingroup$ @MattL Ah thanks! Indeed the addon Object: Align Tools must be active. Otherwise, the mentioned menu entry doesn't exist. $\endgroup$
    – Blunder
    Sep 17, 2022 at 12:47

1 Answer 1



For example:

bpy.ops.object.align(bb_quality=True, align_mode='OPT_3', relative_to='OPT_1', align_axis={'X', 'Y', 'Z'})

As a general tip, after using an operator, go to the Scripting workspace and look at the Info panel on bottom left - the operator is usually there:

  • $\begingroup$ Just a warning: The in the question mentioned addon Object: Align Tools seems to overwrite the operator (Blender 3.3). When it's active the menu entry Object > Transform > Align Objects is replaced by Object > Transform > Align Selected to Active. If you enable the addon it replaces the operator. Then you will get an error if you try to call the operator as shown above. If you disable the addon it removes the menu entry + operator and it's gone! You get a "not found" error when you try to execute the line shown above. $\endgroup$
    – Blunder
    Sep 17, 2022 at 13:07
  • $\begingroup$ Thanks for the help so far. This is starting to drive me a bit mad... I'm trying to write a super simple script that creates an empty and matches the position and rotation of a select object (or multiple objects) Your example almost works for the position, but the original selected object moves ( I want it to stay where it is) Any ideas? $\endgroup$
    – MattL
    Sep 17, 2022 at 13:28
  • $\begingroup$ @MattL en.wikipedia.org/wiki/XY_problem Maybe you just want to parent your object or use a constraint? $\endgroup$ Sep 17, 2022 at 13:31
  • $\begingroup$ I'd like this code to work for bones too constraining bones in blender is no easy task $\endgroup$
    – MattL
    Sep 17, 2022 at 13:35
  • $\begingroup$ Ok, here's the long question. I'm trying to write a Nullifier script. Nullifier was a command in Softimage 3D that would 'pin' an object(s) in space and allow you to move that objects parent around without moving the pinned object. Or ( in the case of a rig) Allow you to pin the hand effector to a table for example. I've written this same tool in both XSI and Maya but in Blender seems to be a bit more complicated.... $\endgroup$
    – MattL
    Sep 17, 2022 at 13:39

You must log in to answer this question.

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