j-man
01-22-2010, 03:48 PM
Hi,
This script will align all of the selected objects to the current view x minimum. It's not without it's problems though, if the current view is a user viewport then it works only half of the time depending on the direction of the view. It works for all other othographic views.
I can't quite work out how to get that final bit working, can you help?
Select a bunch of objects and execute the script. be warned though, it will align to the bounding box (not for perspective views!)
(
sel=selection as array -- get the selections as an array.
tm=(inverse (viewport.getTM())) -- get the current screen coordinate matrix.
selpos=#() -- set an array to hold the positions of the objects in the selection set.
in coordsys tm selpos=for s in sel collect s.pos.x -- collect all of the object positions in the screen coordinate system.
t=tm.row1
m=0
m=t[1]+t[2]+t[3] -- let's work out if it the normal or reverse view by adding each axis of the TM row1 (answer will be positive or negative),
if m<0 then -- collect the min or max value depending on the view (normal or reverse)
(
in coordsys tm seladj=for s in sel collect s.max.x
) else
(
in coordsys tm seladj=for s in sel collect s.min.x
)
v=amin seladj -- get the lowest position in the selection set
newpos=for x=1 to sel.count collect (v+selpos[x]-seladj[x]) -- set the target values to the lowest position, and adjust for object width
for j=1 to sel.count do -- set the new positions
(
in coordsys tm sel[j].pos.x=newpos[j]
)
)
Thanks,
Josh.
This script will align all of the selected objects to the current view x minimum. It's not without it's problems though, if the current view is a user viewport then it works only half of the time depending on the direction of the view. It works for all other othographic views.
I can't quite work out how to get that final bit working, can you help?
Select a bunch of objects and execute the script. be warned though, it will align to the bounding box (not for perspective views!)
(
sel=selection as array -- get the selections as an array.
tm=(inverse (viewport.getTM())) -- get the current screen coordinate matrix.
selpos=#() -- set an array to hold the positions of the objects in the selection set.
in coordsys tm selpos=for s in sel collect s.pos.x -- collect all of the object positions in the screen coordinate system.
t=tm.row1
m=0
m=t[1]+t[2]+t[3] -- let's work out if it the normal or reverse view by adding each axis of the TM row1 (answer will be positive or negative),
if m<0 then -- collect the min or max value depending on the view (normal or reverse)
(
in coordsys tm seladj=for s in sel collect s.max.x
) else
(
in coordsys tm seladj=for s in sel collect s.min.x
)
v=amin seladj -- get the lowest position in the selection set
newpos=for x=1 to sel.count collect (v+selpos[x]-seladj[x]) -- set the target values to the lowest position, and adjust for object width
for j=1 to sel.count do -- set the new positions
(
in coordsys tm sel[j].pos.x=newpos[j]
)
)
Thanks,
Josh.
