The python script takes a selection of vertices and straightens them. This is done by moving those vertices perpendiculary to a defined main vector.
The script supports the following component types (multi selection):
Polygon Edge (
Curve Vertex (
Currently there a three modes of defining the main vector:
maxDistance(default): Take the vetices with the longest distance to each other and align the rest to that vector.
firstTwo: Take the first two selected vertices and align the rest to that vector. Important: See hint selection order at installation description.
lastTwo: Take the last two selected vertices and align the rest to that vector. Important: See hint selection order at installation description.
- Select at least three components (vertices, edges ... see supported types) you would like to straighten.
Call the script. The mode can be one of the three mentioned ones.
from straighten_components import *
The script was tested on Windows 7 64bit with Maya 2012 to 2016. As it does not use any platform dependent code, it should work for Linux and Mac OS X as well.
Where to put the file straighten_components.py?
1) You basically have to put the script in the scripts folder either in a self defined path (
MAYA_SCRIPT_PATH) or just into Maya's default project:
- Linux: $HOME/maya
- Mac OS X: $HOME/Library/Preferences/Autodesk/maya
- Windows: \Users\\Documents\maya
Another solution would be to source the script manually via the folowing python code:
import sys sys.path.append('MY_PATH') from straighten_components import *
For further information. There is a detailed description how to Installing a Maya plug-in in the Autodesk Knowledge Base.
2) Inside Maya, open up the script editor. Then copy the following lines into a python tab (not MEL!):
from straighten_components import * straighten_components(mode="maxDistance")
3) If you want a shelf button, just select those two lines above and drag the selection up to the shelf using your Middle Mouse Button.
Furthermore, in order to use the modes
lastTwo you need to make sure that you have activated the tracking of the selection order. To do this you have those options:
- Turn the option on in Maya preferences:
Preferences > Selection > Track selection order
- Python call:
import maya.cmds as cmds cmds.selectPref(trackSelectionOrder=True)
- Mel call:
selectPref -trackSelectionOrder true ;