Macro StraightenObject

Context
This macro has been written mainly to re-align imported objects (eg. STEP) with main FreeCAD planes/axis.

Usage
Functionally, the macro will use one or both of following reference items to straighten (rotate & move) the object(s) :
 * Face : the selected face will be set coplanar with XY plane, its center mass being set at the origin
 * Edge (or 2 vertexes) : the selected edge will be aligned with the Y axis

To use the macro, select the reference item(s), eventually other objects, then run the macro. If you want to align your object with other plane/axis, use the macro then the Transform function of FreeCAD. See "Details" chapter for multi-object selection.

Installation
The macro is available through Addon Manager. Code is provided on this page for convenience in case user system doesn't have git-python. Though it should be up-to-date, latest release is always available at FreeCAD-macro repository

For more detailed explanations, see the How to install macros page.

Details
Below a table presenting the different cases that are handled by the macro :

The macro will perform the following checks :
 * If the reference face is perpendicular to the reference edge, the latter will be ignored (warning notification in the status bar)
 * If the reference face isn't a flat one, weird result may happen (warning notification in the status bar)

When you select several object, the macro will propose 2 options to apply the straightening :
 * Parent : the macro will try to find a common parent to all selected objects :
 * If no one is found, the macro fails with an error notification in the status bar
 * If one or more is found, the transformation is applied on the hierarchically lower one
 * Multiple : the transformation is applied on each selected object separately

To Be Completed with picture example

Limitations

 * Reference items shall all belong to the first selected object. Reference items among several objects is not supported at this time
 * Straightened object(s) shall be in a coordinate system corresponding to the global one. If you used Part container(s) to locate your objects, you should first use Macro PlacementAbsolufy on your model. If this condition isn't fulfilled, weird things can happen.

Forum discussion
For any feedback (bug, feature request, comments, ...), please use this forum thread : https://forum.freecadweb.org/viewtopic.php?f=22&t=35191

Code
ToolBar Icon

Macro_StraightenObject.FCMacro