align object by selected edge

I couldn't find anything in the search....maybe it exists already?

I wanted a script to align the mesh based on selected edge..straighten it in X, Y OR Z

https://www.dropbox.com/s/4k0ybtaccrbil7f/alignobjectbyedge.jpg

Comments

Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
MerlinEl's picture

maybe this? fn

maybe this?

fn alignObjectToSelectedEdge obj_src = (

local obj_trgt = (selection as Array)[1]
if classOf obj_trgt != Editable_Poly do return false
local edges = (polyOp.getEdgeSelection obj_trgt) as Array
if edges.count == 0 do return false
local everts = (polyOp.getVertsUsingEdge obj_trgt edges[1]) as Array
local p1 = polyOp.getVert obj_trgt everts[1]
local p2 = polyOp.getVert obj_trgt everts[2]
local dir = normalize (p2 - p1)
local tm = matrixFromNormal dir
tm.row4 = (p1 + p2) / 2
undo "Align object to Edge" on obj_src.transform = tm
)

alignObjectToSelectedEdge $Dummy002

Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.