macroScript autoTransformConstraints category:"studioScripts" --category where the script will appear in the customize Ui toolTip:"autoTransformConstraints" --how the name appears in the customize ui list ( global pt1 = undefined /*============================================= updateTransTool =============================================*/ function updateTransTool constraint = ( local activeViewport = viewport.getType() try (toolmode.axisConstraints = constraint) catch(print"ERROR!!!") /* if( activeViewport == #view_persp_user or activeViewport == #view_iso_user ) then ( try( toolmode.axisConstraints = constraint ) catch( print "ERROR: Unable to set axis contraint!!!" ) ) else if( activeViewport == #view_top or activeViewport == #view_bottom) then ( try( toolmode.axisConstraints = #XY ) catch( print "ERROR: Unable to set axis contraint!!!" ) ) else if( activeViewport == #view_right or activeViewport == #view_left) then ( try( toolmode.axisConstraints = #YZ ) catch( print "ERROR: Unable to set axis contraint!!!" ) ) else if( activeViewport == #view_front or activeViewport == #view_back) then ( try( toolmode.axisConstraints = #ZX ) catch( print "ERROR: Unable to set axis contraint!!!" ) ) else if( activeViewport == #view_camera ) then ( try( toolmode.axisConstraints = constraint ) catch( print "ERROR: Unable to set axis contraint!!!" ) ) else ( print "WARNING: Using else case viewport type!!!" try( toolmode.axisConstraints = #XY ) catch( print "ERROR: Unable to set axis contraint!!!" ) ) */ ) /*============================================= choseAxis =============================================*/ function choseAxis myVector = ( local returnAxis local zRotNeg = Matrix3 [0,1,0] [-1,0,0] [0,0,1] [0,0,0] local temp local mat try ( mpTM = $miauuWorkPlane.transform mat = mpTM mpTM = inverse mpTM ) catch ( mat = Matrix3 [1,0,0] [0,1,0] [0,0,1] [0,0,0]) local xAxis = dot(normalize myVector) (normalize mat.row1) local yAxis = dot(normalize myVector) (normalize mat.row2) local zAxis = dot(normalize myVector) (normalize mat.row3) if ( abs(zAxis) >= abs(xAxis) and abs(zAxis) >= abs(yAxis) ) then (return #Z) else if ( abs(yAxis) >= abs(xAxis) and abs(yAxis) >= abs(zAxis) ) then (return #Y) else (return #X) ) /*============================================= setTransformConstraint =============================================*/ function setTransformConstraint = ( local vpTm = inverse( getViewTM() ) local camLook = -1 * vpTm.row3 local nearestAxis local constraint local pt2 local screenVec local constrainDir if( pt1 != undefined ) then ( mousePos = mouse.screenpos pt2 = [ mousePos.x, mousePos.y, 0 ] upDown = dot( normalize( pt1 - pt2 ) ) ( [0,1,0] ) leftRight = dot( normalize( pt1 - pt2 ) ) ( [1,0,0] ) if( abs( upDown ) < abs( leftRight ) ) then ( constrainDir = vpTm.row1 ) else ( constrainDir = vpTm.row2 ) nearestAxis = choseAxis( constrainDir ) updateTransTool( nearestAxis ) ) else ( nearestAxis = choseAxis( camLook ) if( nearestAxis == #X ) then ( constraint = #YZ ) else if( nearestAxis == #Y ) then ( constraint = #ZX ) else ( constraint = #XY ) updateTransTool( constraint ) ) if( keyboard.controlPressed ) then ( ctrlPressed = true ) else ( ctrlPressed = false ) ) function dispatch = ( if( pt1 == undefined ) then ( if( keyboard.controlPressed ) then ( pt1 = [mouse.screenpos.x, mouse.screenpos.y, 0] ) else if( not keyboard.controlPressed) then ( pt1 = undefined ) ) else if( not keyboard.controlPressed) then ( pt1 = undefined ) setTransformConstraint() ) rollout autoConstraintsRlt "AutoContraint" ( timer dispatcher "dispatcher" interval:50 active:true button closeDialogBtn "Exit" on dispatcher tick do ( dispatch() ) on closeDialogBtn pressed do ( dispatcher.active = false DestroyDialog autoConstraintsRlt ) ) setRefCoordSys #world createDialog autoConstraintsRlt style:#(#style_border, #style_titlebar) )