View Single Post
# 2 18-02-2012 , 10:50 AM
Registered User
Join Date: Jan 2012
Posts: 6
Alright, seems no one here could be bothered to point me to "Snap Align Object" -> "3 Points to 3 Points", but luckily I found the answer elsewhere...

Anywho, I ended up writing a small script (works for me at least) that may be of help for someone else, here goes:

Code:
// this finds the name of the group the selected object belongs to
string $p[] = `listRelatives -fullPath` ;
$p = stringToStringArray( $p[0], "|") ;
$gOriginal = $p[0] ;

// duplicate the selected object and move it to root
duplicate -rr -n refOrig ;
parent -w refOrig ;

// move the object to the root of GROUP the selected object belongs to
parent refOrig $gOriginal ;

// you may or may not want this, I had a subgroup inside the group
// and wanted the duplicated object to be the first object in it
reorder -relative -1 refOrig ;

// create a new reference plane at 0, 0, 0. 100 units wide/deep
nurbsPlane -p 0 0 0 -ax 0 1 0 -w 100 -lr 1 -d 1 -u 1 -v 1 -ch 1 -n refPlan ;

// you may want to change this, I wanted the corner to be at 0, 0
// so X and Y goes -50. for my purpose I also moved it up 75 units.
setAttr "refPlan.translateX" -50 ;
setAttr "refPlan.translateZ" -50 ;
setAttr "refPlan.translateY" 75 ;

// select 3 vertices on the original object
select -r refOrig.cv[0][0] ;
select -tgl refOrig.cv[0][1] ;
select -tgl refOrig.cv[1][1] ;

// select 3 vertices on the reference plane
select -tgl refPlan.cv[1][0] ;
select -tgl refPlan.cv[1][1] ;
select -tgl refPlan.cv[0][1] ;
Basically, what I do is this; I select a single part/plane on the group that needs to be straightened that I know is supposed to be straight (flat on the ground). Then I run the above script which creates a duplicate of the selected object + a reference plane at 0, 0, 0 (I move it in X, Y and Z axis with setAttr above, you may want to get rid of or change those). The script also selects 3 points from the duplicate of the original object and then 3 points on the newly created reference plane. After that I only need to select "3 Points to 3 Points", select "Parent" from the dialog (the script moves the duplicate to the root of the group the original is part of).

Depending on the model, you may have to rotate it anyways, but it should now be a question of 90 degree angles only.

After the straightening is done you should remove the "leftover" refOrig and refPlan objects.

I will not provide any further support for this script, but it may be of help to someone out there user added image