/********************************************************* * Snap and Link version 1.1 * by * Marc Florestant * Copyright 2007 * * * This utility script takes two groups of objects and * matches the transforms of the first group with * the transforms of the second and then links them * together. **********************************************************/ utility snapLink "Snap & Link" ( Global heldObjects, heldTargets, shuffledElements = #() /* Interface Setup */ button getObj "Get Objects" pos:[31,25] width:75 height:24 toolTip:"Ready Selected Objects for Operation" button rand "RND" pos:[106,25] width:25 height:24 toolTip:"Press to Randomize Object Assignment" button getTarg "Get Target" pos:[31,60] width:100 height:24 toolTip:"Ready Selected Targets for Operation" button clr "Clear" pos:[56,95] width:50 height:24 toolTip:"Clears Out All Elements" button doIt "Do It!" pos:[56,140] width:50 height:24 toolTip:"Execute Operation" label credit "Marc Florestant" pos:[44,190] width:73 height:16 label copyRight "Copyright 2007" pos:[44,205] width:72 height:16 /* End Interface Setup */ /* Define Functions */ fn snapAndLink selObj targ loopNum = ( for i = 1 to loopNum do ( selObj[i].transform = targ[i].transform selObj[i].parent = targ[i] )--end for loop )--end snapAndLink function fn resetButtons =( getObj.text = "Get Objects" --reset the button text getTarg.text = "Get Target" heldObjects = 0 --clear out the variables to free up memory heldTargets = 0 )--end resetButtons fn shuffleObjects origArr =( --this function randomizes elements in an array and puts them in another while shuffledElements.count < origArr.count do ( holdVal = random 1 origArr.count appendIfUnique shuffledElements origArr[holdVal] heldObjects = shuffledElements ) )--end shuffleObjects /* end Define Functions */ /* Processing */ on getObj pressed do -- Pull in the objects to be aligned ( heldObjects = selection as array getObj.text = heldObjects.count as string +" objects" )--end on getObj on rand pressed do --Randomize the objects ( heldObjects = selection as array shuffleObjects heldObjects heldObjects = shuffledElements getObj.text = shuffledElements.count as string +" objects" ) --end Randomize the objects on getTarg pressed do -- Pull in targets ( heldTargets = selection as array getTarg.text = heldTargets.count as string +" targets" )--end on getTarg on clr pressed do ( resetButtons() )--end on clr on doIt pressed do -- ( if heldObjects == 0 or heldTargets == 0 then ( messageBox "Pick Some Objects and Targets" ) else ( if heldObjects.count != heldTargets.count then ( messageBox "The number of elments do not match" resetButtons() ) else ( undo on ( snapAndLink heldObjects heldTargets heldTargets.count resetButtons() ) ) ) )--end doIt /* End Processing */ )