-- ****************************************** -- -- *** align-script v1.2 by le1setreter *** -- -- *** apr2009 *** -- -- ****************************************** -- -- CREDITS: Many Thanks to all the people that helped me. -- you can visit and contact me at http://www.le1setreter.de -- Edited Anton Morozov 2015.02.19 macroScript Obj2Spline_Aligner category:"# Scripts" toolTip:"Obj2Spline Aligner v1.6.1" ( clearselection() rollout obj2splRoll "obj2spl aligner" width:184 height:496 ( local origObj -- the object that should be instanced local origObjRotationX -- the original rotation pvalues local origObjRotationY -- the original rotation pvalues local origObjRotationZ -- the original rotation pvalues local origObjScale -- the original scale of the object local targetSpline -- the spline where the the instances are aligned to local targetSpline_old local instanceCount -- the amount of instances local instanceArray = #() -- array for new createt instance objects local scaleDir -- direction for scaling local rotateAxis -- the axis in which object and instances have to rotatet -- selecting the object to clone/align: pickbutton chooseObj "pick object" pos:[16,16] width:152 height:21 toolTip:"pick the object to be duplicated" -- selecting the spline to align on: fn validSpline spl = (classof spl == Line) or (classof spl == SplineShape) pickbutton chooseSpl "pick spline" pos:[16,42] width:152 height:21 filter:validSpline toolTip:"pick the line/spline for alignment of objects" -- origObject rotations: button rotXBtn "rot X" pos:[24,297] width:40 height:21 toolTip:"rotate instances around x-axis" button rotYBtn "rot Y" pos:[72,297] width:40 height:21 toolTip:"rotate instances around y-axis" button rotZBtn "rot Z" pos:[120,297] width:40 height:21 toolTip:"rotate instances around z-axis" -- origObject scaling: button scaleUpBtn "scale up" pos:[24,329] width:65 height:21 toolTip:"scale up instances" button scaleDownBtn "scale down" pos:[96,329] width:65 height:21 toolTip:"scale down instances" -- setting amount of duplicates/instances spinner instCount "" pos:[104,120] width:60 height:16 enabled:true range:[2,1000,2] type:#integer toolTip:"set amount of instances" spinner spacing "" pos:[104,144] width:60 height:16 enabled:false range:[0.1,9999,100] type:#worldunits toolTip:"set spacing betwin instances" spinner offset "" pos:[104,168] width:60 height:16 enabled:true range:[-9999,9999,0] type:#float scale:0.01 toolTip:"set spacing betwin instances" -- preview Button button prevBtn "create/update view" pos:[16,200] width:104 height:21 toolTip:"create/update view" -- cancel Button button redoBtn "reset" pos:[128,200] width:39 height:21 toolTip:"delete instances" button bt_snapshot "snapshot" pos:[32,234] width:120 height:21 toolTip:"create/update view" -- infobox label lab10 "" pos:[90,196] width:0 height:13 -- select spline button button slctSpl "select/edit spline vertex" pos:[24,393] width:136 height:21 toolTip:"select spline" -- select spline button button slctObj "select/edit object vertex" pos:[24,423] width:136 height:21 toolTip:"select object" -- move instances to (new) layer button intoLayer "export all into new layer" pos:[24,457] width:136 height:21 toolTip:"(create and) movie instances into (new) layer" checkbox chk_count "Count:" pos:[16,120] width:64 height:14 checked:true checkbox chk_spacing "Spacing:" pos:[16,144] width:64 height:14 checked:false label lbl3 "Ofset:" pos:[32,168] width:56 height:16 label lbl4 "Total in Array:" pos:[16,73] width:72 height:16 label lbl_total_count "0" pos:[96,73] width:72 height:16 GroupBox grp2 "Create" pos:[8,97] width:168 height:168 GroupBox grp3 "Transform" pos:[8,273] width:168 height:88 GroupBox grp4 "Edit" pos:[8,369] width:168 height:120 fn chengStat stat = ( if instanceArray.count > 0 then bt_snapshot.enabled = true else bt_snapshot.enabled = false if stat == 1 do ( chk_count.state = true chk_spacing.state = false instCount.enabled = true spacing.enabled = false ) if stat == 2 do ( chk_count.state = false chk_spacing.state = true instCount.enabled = false spacing.enabled = true ) lbl_total_count.caption = instanceArray.count as string ) fn cloneAlign = ( if (instanceArray.count >= 1) and (targetSpline_old == targetSpline) then ( for i = 1 to instanceArray.count do ( delete instanceArray[i] ) ) -- end if instanceArray = #() targetSpline_old = targetSpline if chk_count.state do ( k = instCount.value - 1 pos = k ) if chk_spacing.state do ( k = floor (curvelength(targetSpline)/spacing.value) pos = curvelength(targetSpline)/spacing.value ) for i = 0 to k do ( percentState = 100.0/pos * i percentState += offset.value - (100.0/pos * floor (offset.value/(100.0/pos))) if (percentState <= 100) and (percentState >= 0) do ( new_copy = instance origObj --instance the object new_copy.name = uniquename (origObj.name+"_Instance") --rename it append instanceArray new_copy -- add to instance array -- print instanceArray new_copy.pos.controller = path follow:true path:targetSpline constantVel:true percent:percentState allowUpsideDown:on -- align/follow path new_copy.transform = origObj.transform --copy the TMatrix to orient correctly ) ) -- end for gc light:true chengStat(0) ) --end fn fn deleteInstances = ( for k = 1 to instanceArray.count do ( delete instanceArray[k] ) -- end for -- empty array instanceArray = #() ) -- end fn fn rotateOrigObj = ( if rotateAxis == "x" do( newRot = origObj.rotation.x_rotation + 90 origObj.rotation.x_rotation = newRot ) -- end if if rotateAxis == "y" do( newRot = origObj.rotation.y_rotation + 90 origObj.rotation.y_rotation = newRot ) -- end if if rotateAxis == "z" do( newRot = origObj.rotation.z_rotation + 90 origObj.rotation.z_rotation = newRot ) -- end if if (instanceArray.count >= 1) then ( for k = 1 to instanceArray.count do ( if rotateAxis == "x" do( newRot = instanceArray[k].rotation.x_rotation + 90 instanceArray[k].rotation.x_rotation = newRot ) -- end if if rotateAxis == "y" do( newRot = instanceArray[k].rotation.y_rotation + 90 instanceArray[k].rotation.y_rotation = newRot ) -- end if if rotateAxis == "z" do( newRot = instanceArray[k].rotation.z_rotation + 90 instanceArray[k].rotation.z_rotation = newRot ) -- end if -- delete instanceArray[k] ) -- end for ) else ( -- messagebox "no array" ) -- end if ) -- end fn -- if object is scaled: fn scaleOrigObj scaleDir = ( if scaleDir == "upDir" do ( scaleSize = [1.1,1.1,1.1] ) -- end if if scaleDir == "downDir" do( scaleSize = [0.9,0.9,0.9] ) -- end if scale origObj scaleSize if (instanceArray.count >= 1) then ( for l = 1 to instanceArray.count do ( scale instanceArray[l] scaleSize ) ) else ( -- nothing ) -- end if ) -- end fn fn manageLayer = ( messagebox "new layer will be activated!" rnd = random 1000 9999 obj2splLayer = LayerManager.newLayerFromName ("obj2spline_"+rnd as string) obj2splLayer.current = true obj2splLayer.renderable = false obj2splLayer.addNode origObj obj2splLayer.addNode targetSpline if (instanceArray.count >= 1) then ( for l = 1 to instanceArray.count do ( obj2splLayer.addNode instanceArray[l] -- delete instanceArray[k] ) -- end for ) else ( -- messagebox "no array" ) -- end if intoLayer.enabled = false ) -- end fn on obj2splRoll open do ( chengStat(0) ) on obj2splRoll close do ( /* origObj.rotation.x_rotation = origObjRotationX origObj.rotation.y_rotation = origObjRotationY origObj.rotation.z_rotation = origObjRotationZ origObj.scale = origObjScale -- max undo */ ) --end on on chooseObj picked obj do ( --see if the user did not cancel the picking... if obj != undefined do( --if he did not, make the box's wireframe red: obj.wirecolor = red origObj = obj --and display the name of the object on the button: chooseObj.text = obj.name origObjRotationX = origObj.rotation.x_rotation origObjRotationY = origObj.rotation.y_rotation origObjRotationZ = origObj.rotation.z_rotation origObjScale = origObj.scale print origObjScale ) --end if ) --end on on chooseSpl picked spl do ( --see if the user did not cancel the picking... if spl != undefined do( --if he did not, make the box's wireframe red: spl.wirecolor = red targetSpline = spl --and display the name of the object on the button: chooseSpl.text = spl.name ) ) --end on on rotXBtn pressed do ( rotateAxis = "x" rotateOrigObj() ) -- end on on rotYBtn pressed do ( rotateAxis = "y" rotateOrigObj() ) -- end on on rotZBtn pressed do ( rotateAxis = "z" rotateOrigObj() ) -- end on on scaleUpBtn pressed do ( scaleDir = "upDir" scaleOrigObj scaleDir ) -- end on on scaleDownBtn pressed do ( scaleDir = "downDir" scaleOrigObj scaleDir ) -- end on on instCount changed val do ( cloneAlign() --instanceCount = val -- print val ) --end on on spacing changed val do ( cloneAlign() ) --end on on offset changed val do ( cloneAlign() ) --end on on prevBtn pressed do ( -- messagebox "do the action" clearselection() cloneAlign() ) --end on on redoBtn pressed do ( deleteInstances() chengStat(0) ) -- end on on bt_snapshot pressed do ( cloneArr = #() for k = 1 to instanceArray.count do ( append cloneArr (instance origObj transform:instanceArray[k].transform) delete instanceArray[k] ) -- end for instanceArray = #() select cloneArr cloneArr = #() chengStat(0) ) --end on on slctSpl pressed do ( clearselection() select targetSpline subobjectLevel = 1 ) -- end on on slctObj pressed do ( clearselection() select origObj if (classof origObj == Editable_Poly) do subobjectLevel = 1 ) -- end on on intoLayer pressed do ( manageLayer() ) -- end on on chk_count changed state do chengStat (1) on chk_spacing changed state do chengStat (2) ) createdialog obj2splRoll )