Align side by side

0 votes
Version: 
1.0
Date Updated: 
05/07/2017
Author Name: 
Khodor Rizk

tool helperpoints --mouse click definition
(
local p
on mousePoint clickp do (p = point name:("point_" + (random 0 100 as string)) pos:worldPoint size: 1 wirecolor:[130,225,40])

on mouseMove clickno do p.pos = worldPoint
)

rollout rlhelperPoints "Helper Points Creation" -- create rollout to fill with buttons
(
button btstart "Start Helping Points" width:125 --this will activate the tool
button snapobjects " Snap objects on Points" width:125
button deletepoints "DELETE all points" width:125 -- this will DELETE the points

-- this STARTS the tool
on btstart pressed do
(
starttool helperpoints
)

on deletepoints pressed do (
try (delete $point_**) catch(messagebox "NO points")
)

on snapobjects pressed do (
undo on
(
ObjForAlign = selection as array
try (select $point_**) catch(messagebox "NO points")
pointcollect = selection as array
max select none
for s =1 to pointcollect.count do
(
try(
ObjForAlign[s].center = pointcollect[s].center

)
catch()
)

)
)

)

rollout rlalign "Align objects Side by Side"
(
spinner gapp "Gap" range:[0,250,0]
button btalign "Arrange" width:125
button selObjForAlign "Select objects" width:125
label countlabel "Khodor Rizk 2017"
-- what happens if pressing Arrange (btalign) ?
on btalign pressed do
(

global ObjForAlign = selection as array
radarray = #()
ObjForAlignCount = ObjForAlign.count
countlabel.text = ObjForAlignCount as string +" Nodes are active"

j=1
while j < ObjForAlignCount do
(
s1 =ObjForAlign[j]
s2 =ObjForAlign[j+1]

-- define the radius of each bounding box
rad1 = (s1.max.x - s1.min.x)/2
rad2 = (s2.max.x - s2.min.x)/2

-- now put each object on its correct position
s2.pos.x = s1.pos.x +rad1 +rad2 +(gapp.value as float)
s2.pos.y=s1.pos.y

-- increment by 1
j +=1

)

)

-- Spinner GAP (the minimal distance) between objects
on gapp changed gappp do
(
try(

radarray = #()
ObjForAlignCount = ObjForAlign.count

j=1
while j < ObjForAlignCount do
(
s1 =ObjForAlign[j]
s2 =ObjForAlign[j+1]

-- define the radius of each bounding box
rad1 = (s1.max.x - s1.min.x)/2
rad2 = (s2.max.x - s2.min.x)/2

-- now put each object on its correct position
s2.pos.x = s1.pos.x +rad1 +rad2 +(gapp.value as float +gappp)
s2.pos.y=s1.pos.y

-- increment by 1
j +=1

)

-- progress bar value changes return to 0
select ObjForAlign
progresss.value = 0
select ObjForAlign

)

catch()
)

on selObjForAlign pressed do select ObjForAlign
)

if wnhlPoints != undefined do closerolloutfloater wnhlPoints
wnhlPoints = newrolloutfloater "Helper Points" 200 240
addrollout rlhelperPoints wnhlPoints
addrollout rlalign wnhlPoints

Additional Info: 

this script allows the user to align his nodes side by side on x axis , minimum boundary to maximum boundary , all on single line

or he may create specific points where he wants the nodes to be .

it is very useful if you want to create brick wall , rails or even to align plants or such accessories on single line or preset points .

this script is done with the simplest algorithm

change it on your own mood .

cheers

AttachmentSize
arrange_side_by_side_on_helper_points.ms3.05 KB