From BlenderWiki

Jump to: navigation, search
Precise Align
Align Objects and set Local Transform Orientation
UI location View3D > Tool Self > Precise Align
Version 1.0 Author(s) Tjeerd Schouten
Blender 2.6 License GPL 3+
Category 3D View Distribution Upload


Executable information
File name space_view3d_precise_align.py
Current version download http://projects.blender.org/tracker/index.php?func=detail&aid=31620&group_id=153&atid=467
Python modules math, mathutils


Links and troubleshooting
Links http://projects.blender.org/tracker/index.php?func=detail&aid=31620&group_id=153&atid=467


Description

It is very difficult and in some cases simply impossible to precisely align objects within Blender. This is ok for organic modeling but unacceptable for mechanical modeling. This script solves that problem.

With this script you can select three vertices and it will create an empty aligned with the normal and an edge of that face. This empty can be parented to the object and this way any face on the object can be precisely aligned with any face on another object.

Additionally, you can change the local transform orientation of an object in rotation as well, instead of just the build-in set origin feature. Combined with the feature above, you can precisely align the local transform of an object with a custom face created by three vertices and an edge of that face.

Installation

  • Put the script in /Blender/2.63/scripts/addons
  • Activate script (press checkbox) in File > User Preferences > Add-Ons > 3Dview > Precise Align
  • "Precise Align" subpanel will appear in the 3D View Tool Shelf (on left side of screen, press T to view panel).

Features

Edit mode:

  • Create an Empty and align it with a face specified by three vertices and an Edge on that face.
  • Change the Normal, Edge, and Tangent vector direction on the fly.
  • Map the Normal, Edge, and Tangent to any X,Y,Z axis.
  • Swap the location of the Empty to each vertex.
  • Option to automatically parent the Empty to the active Object.
  • Change size of connected empty on the fly.
  • Automatically sets the Empty to X-Ray and Arrows display mode.

Object mode:

  • Select any empty in the scene and set it as the source for the Local Transform.
  • Set the Local Transform Rotation of an Object to the rotation of an empty.
  • Set the Local Transform Position of an Object to the position of an empty.
  • Align the rotation of an Object with the rotation of an Empty.
  • Align the position of an Object with the position of an Empty.

Usage

Workflow

  • Select the Object you want to align and go to Edit mode.
  • Press "a" to deselect all.
  • Select the "Vertex Select" icon on the bottom panel and select three vertices.
  • Select "Create Empty". An Empty will appear at one of the Edge vertices and it will be aligned with the face normal and edge vector. Note the name of the Empty in the "Source Transform:" field. The name is based on the Object name which is active. If you make another Object active in Edit mode which has a Source Transform added to it as well, the script will automatically select the correct empty based on the Object name. Because of this, do not manually add an Empty to the scene with the same naming convention.
  • Use the "Flip Vector", "Map Vector", and "Swap Empty Origin" items to further refine the orientation of the empty.
  • If you want to change your mind and use other vertices after an Empty already has been created, just select the other vertices and then select one of the Flip Vector items to update the Empty position.

Workflow continued: Aligning Objects

  • Let's say we want to align the face, edge, and vertex of the two objects shown here:

Align1.png

  • Set "Parent to Object" to make the Empty the parent of the Object.
  • Repeat the steps above for another Object.
  • Make sure that the vector flipping and mapping makes sense so the objects will be correctly aligned. The scene should now look something like this:

Align2.png

  • Go to Object mode and select a twice to deselect all.
  • If you want to align Object A to Object B, select the Empty from Object A first, hold shift, then select the Empty from Object B. Alternatively, you can select only one object, and it will be automatically aligned to it's Source Transform.
  • Select "Align Object". The selected Object will be aligned with the active Object. If only one Object is selected, the selected Object will be aligned to the Source Transform.
  • If you want to align the Object location as well, make sure that "Align Object Position" is selected when pressing "Align Object"
  • The scene should now look something like this:

Align3.png


Workflow continued: Setting Local Transform Orientation and Position

  • Let's say the Local Transform Orientation is rotated incorrectly as shown here:

Local1.png

  • Place an Empty with the correct orientation using the first workflow steps. The scene should now look something like this:

Local2.png

  • Go to Object mode and select "a" to deselect all.
  • To set the local transform of an Object to the transform of an Empty, select the Object first, hold shift, then select the Empty. Alternatively, you can select only one object, and it will be automatically aligned to it's Source Transform.
  • Select "Align Object Local Transform". Note that all parent information of the Object will be lost when doing this (Object will be placed in the root of the tree). All children of the Object will be left alone though.
  • If you want the Local Transform Position to move to the location of the empty as well, make sure you select "Align Local Transform Position" when selecting "Align Object Local Transform".
  • If you want the Local Transform Position to be located at the center of the object, you need to place the 3d cursor there first. This can be done by going to Edit mode, Press the Vertex Select button on the bottom of the 3d view. Select "a" twice to select all, or shift-click to select other vertices. Then press shift-s > Cursor to Selected. Then select "Origin to 3D Cursor". Alternatively, you can place the Empty at the center of the object with shift-s > Selection to Cursor. Then press "Align Object" with "Align Local Transform Position" selected.
  • The scene should now look something like this:

Local3.png


Settings

-Object Mode:

  • Source Transform: The Empty Object which will be used as a reference for the transform, if one Object is selected and an Empty for it is available. If no Empty is available, the active Object will be shown. If multiple Objects are selected, the active Object will be shown as well.
  • Align Local Transform Position: Set the local Transform position to the selected Empty when "Align Object Local Transform" is pressed.
  • Align Object Position: Sets the position of the selected Object to the position of the active Object when "Align Object" is pressed.
  • Align Object: Aligns the selected Object rotation to the active Object rotation.

-Edit Mode:

  • Source Transform: The Empty Object which is added to the object.
  • Normal: Flips the face normal vector.
  • Edge: Flips the Edge vector.
  • Tangent: Flips the vector which is a tangent from the Normal and Edge vector (cross product)
  • Swap Empty Origin: Swaps the vertex where the Empty is connected.
  • Map Vector (X,Y,Z): Maps the Normal, Edge, and Tangent vector to one of the axis. Be sure you do not have two or more same axis set.
  • Create Empty: Creates an empty and sets its transform according to the settings. The Source Transform will be set to this empty
  • Parent to Object: Automatically parent to Empty to the Object. Useful for aligning Objects.
  • Size: The size of the Source Transform Empty which is added to the Object.


User Interface

Edit Mode
Object Mode

Troubleshooting

-I can't see the "Create Empty" Button.

  • Check you have correctly installed the script.
  • The "Precise Align" menu is on the Tool Self panel (press t to view).
  • You have to be in Edit mode to create an Empty.

-I press "Create Empty", but nothing happens.

  • Three vertices must be selected
  • Map Vector must not have two or more the same axis types. For example, you can't have X,Z,Z. It must be for example X,Z,Y
  • Only a right hand coordinate system is valid. If a left handed coordinate system is created, an Empty will not be created

- I change the Flip Vector or Map vector items but nothing happens.

  • The item "Source Transform" must indicate an Empty. If it does not, add an Empty first.

- I select an align button in Object mode but nothing happens.

  • Two Objects must be selected. Alternatively, only one Object can be selected, but it's Source Transform Empty must be available.
  • The Empty is a right hand coordinate system. Go back to Edit mode and change it.

Known Issues

  • When using the Align Object Local Transform feature, The parents of the Object will be cleared (the object will be placed in the root of the tree), but any children will be left alone.
  • Note the name of the Empty in the "Source Transform:" field. The name is based on the Object name which is active. If you make another Object active in Edit mode which has a Source Transform Empty added to it as well, the script will automatically select the correct empty based on the Object name. Because of this, do not manually add an Empty to the scene with the same naming convention.
  • Swapping the Edge vertex might change the orientation of the Empty.
  • In order to update the error message of the Empty when coming from Object mode with an Empty already created, cycle one of the Flip Vector or Map Vector items.

Change Log

v0.1

First release


v0.2

-Added "Set Source Empty" button.

-Parent status of empty is updated if related checkbox is changed.

-Fixed a bug which rotated the entire Object instead of just the local transform when "Align Object Local Transform" is selected with "Source Empty Fixed" set to Yes.

-Fixed a bug which prevented the "Align Object Local Transform" feature from doing anything when "Source Empty Fixed" is set to Yes. and both the Object and the Empty are selected with the Empty being active.


v0.3

-Added align feature

-Added feature which automatically clears any parented Objects when using the Align Object Local Transform feature. This is done because if the Object has any parents, it will mess up the transformation setting.


v0.4

-Fixed a bug which caused a script crash when using in anything other then Scripting view.


v0.5

-Slightly modified the name of some panel items.

-Automatic x-ray on for Empty.

-Fixed a bug with the Align Object logic which made it behave incorrectly.


v0.6

-Removed "Source Empty Fixed" item. Now, if a Source Empty is shown, it is Fixed as well.


v0.7

-Fixed a bug which caused a crash of the script.

-Added "Origin to 3D Cursor" button.


v0.8

-Fixed a bug (similar to the one in v0.7) which caused a crash as well.

-Removed the "Set Source Empty" button. The source empty will now be given a name based on the object to which it is added. This name is used as a reference to keep track of which Empty belongs to which object.


v0.9

-Can now set the position of the Local Transform or the Object orientation separately.

-Changed layout and changed "Source Empty" to "Source Transform".

-Fixed a bug with Align Object: Position. It did now work correctly when the active object was a child of another object (used local position instead of global).

-Fixed a bug with the Align Local Transform logic which caused incorrect rotations.

-Fixed a bug which caused matrix trashing caused by the user creating a left handed instead of a right handed coordinate system.

-Feedback given if the Empty Coordinate System is invalid.

-Changed selection system from one Face and an Edge to 3 vertices instead. This provides more flexibility for Coordinate System creation.


v1.0

-The parent is automatically removed when using Align Object Rotation as well, otherwise the rotation doesn't work.

-Removed error saying that context.active_object.name does not exist.