Originally posted by mmrender
View Post
Code:
try(destroyDialog AlignBboxToObject)Catch() --arrays Obj_arr = #() list_arr = #() --functions fn AlignBBoxToFirstNormalfn1 theObject = --Function written by Borislav Petrov ( theCurrentTM = theObject.transform --this is the current transformation theMesh = snapshotasmesh theObject --get the world space TriMesh theTM = matrixFromNormal (getFaceNormal theMesh 1) --build a matrix from normal delete theMesh --delete the TriMesh from memory theTM.row4 = theCurrentTM.row4 --set the position of the new matrix to the old pos theObject.transform *= inverse theTM --transform out of world space resetXForm theObject --reset the XForm convertToMesh theObject --collapse the stack theObject.transform = theTM --transform back into world space ) fn AlignBBoxToFirstNormalfn2 theObject = --Function written by Borislav Petrov ( theCurrentTM = theObject.transform theMesh = snapshotasmesh theObject theZ = normalize (getFaceNormal theMesh 1) theFace = getFace theMesh 1 theY = normalize ((getVert theMesh theFace.y)-(getVert theMesh theFace.x)) theX = normalize (cross theY theZ) theTM = matrix3 theX theY theZ theCurrentTM.row4 theObject.transform *= inverse theTM resetXForm theObject convertToMesh theObject theObject.transform = theTM ) fn Obj_filt obj = isKindOf obj GeometryClass fn objList = ( list_arr = for o in Obj_arr where isValidNode (obj = getNodeByName o) collect obj ) --rollouts rollout AlignBboxToObject "Align Bounding Box" width:200 height:200 ( button btn_Load "load" ListBox lst_objs button btn_doFn1 "Function 1" across:2 button btn_doFn2 "Function 2" on btn_Load pressed do ( Obj_arr = #() SelObj = selectByName title:"List Objects" filter:Obj_filt() if SelObj != undefined do ( for i in SelObj do ( append Obj_arr i.name objList() ) ) if Obj_arr.count != 0 then ( lst_objs.items = Obj_arr ) ) on btn_doFn1 pressed do ( deselect for o in list_arr do ( AlignBBoxToFirstNormalfn1 o ) ) on btn_doFn2 pressed do ( deselect for o in list_arr do ( AlignBBoxToFirstNormalfn2 o ) ) on AlignBboxToObject closed do ( Obj_arr = #() list_arr = #() ) ) CreateDialog AlignBboxToObject width:200 height:200
Comment