I would like a script that does two things with the option of doing both or each individually.
It is just like the Distribute tools for layers in Photoshop.
Example: You have a scene with a handful of objects that you want to distribute.
http://www.scriptspot.com/files/distance.png
Option 1: The script takes the selected objects and without moving/adjusting the end objects (which would be the two objects furthest from each other) the script would align them all. Think of it as if you made a straight line between the 2 end objects and then moved each object in between to match that line.
http://www.scriptspot.com/files/distancealign.png
Option 2: Would take all the objects except for the 2 end objects and then evenly distribute those objects along the virtual line that would be drawn between the 2 end objects. Which would result in all the objects being evenly space apart based on there pivot or bounding box.
http://www.scriptspot.com/files/distancedistribute.png
Thanks
JokerMartini
By
Comments (15)
Comment policy
Distribute script
I have been looking for a working tool for distributing objects in space for a long time. As a result, I am developing my own.
At the moment, it can distribute not only objects, but also vertices in splines and meshes. He selects the first and last objects himself and sorts them by position in space (not by selection order). That is, everything works with one button without unnecessary windows. Highlighted - clicked the button on the panel and that's it. Or you can add keyboard shortcuts.
Download from the Github
subscribe for updates.
Attachments
Distribute different objects - how I can do it???
Please explain how to use this script, evenly distribute the objects that have different sizes? The script does equal intervals between the centers of the objects. But how to make equal intervals between the objects???
nice script, but when I have objects which are not at 0,0,0 and I check "Distribute" and then "align in X", the scripts move the objects back to the x axis? the objects doesn't stay at their position (the two guide objects at the sides)?
Attachments
Check out this. It works way better.
http://jokermartini.com/2011/05/09/get-in-line/
Great work Garp. This is a very useful script you've created here.
I've noticed that when you use the option of the first and second end objects and hit the buttons that the end objects tend to move? Why is that?
Here you go.
Attachments
Garps
Hey Garp, Great script. I took what you wrote and threw it into a UI as well as tried to go ahead and add the option of choosing a start or end object if the user wants to.
It is a bit finiky. I figured I would post it in here and seek some help.
This is a great script.
I just added variables objA and objB for the option of a start and end obj. I'd like to add checkboxes which would allow users to choose X Y or Z
(
local distrib = true
local cnt = selection.count
local obj1, obj2
local max_dist = 0
local objA = undefined
local objB = undefined
fn AutoLineup =
(
if cnt > 2 do
(
for i = 1 to cnt - 1 do for j = i + 1 to cnt do
(
local dist = distance selection[i] selection[j]
if dist > max_dist do
(
if objA ==undefined then
(
obj1 = selection[i]
)
else
(
obj1 = objA
)
if objB ==undefined then
(
obj2 = selection[j]
)
else
(
obj1 = objB
)
max_dist = dist
)
)
local dum = dummy pos:obj1.pos dir:(obj2.pos - obj1.pos)
in coordsys dum
(
local arr = selection as array
fn order o1 o2 = o1.pos.z - o2.pos.z
qsort arr order
local dz = obj2.pos.z / (cnt - 1)
for i = 2 to cnt - 1 do
(
obj = arr[i]
obj.pos.x = obj.pos.y = 0
if distrib do obj.pos.z = (i - 1) * dz
)
)
delete dum
)
)
rollout rlAlignDistribute "Lineup"
(
button btnClearStart "X" width:20 height:20 pos:[2,2]
button btnClearEnd "X" width:20 height:20 pos:[2,24]
pickbutton pkbtnPickStart "Start Object" width:126 height:20 pos:[22,2]
pickbutton pkbtnPickEnd "End Object" width:126 height:20 pos:[22,24]
button btnAutoLineUp "Auto Lineup" width:146 height:24 pos:[2,46]
on btnAutoLineUp pressed do
(
AutoLineup()
)
on pkbtnPickStart picked obj do
(
if obj != undefined then
(
pkbtnPickStart.text = obj.name
objA = obj
)
)
on pkbtnPickEnd picked obj do
(
if obj != undefined then
(
pkbtnPickEnd.text = obj.name
objB = obj
)
)
on btnClearStart pressed do
(
pkbtnPickStart.text = "Start Object"
objA = undefined
)
on btnClearEnd pressed do
(
pkbtnPickEnd.text = "End Object"
objB = undefined
)
)
createDialog rlAlignDistribute 150 72
)
Great
That is great Garp.
I'm going to try and make it work for all axis. X Y and Z for aligning.
This one seems to work.
(could use a rollout though)
Solution
All i need to do really to make this work from here is figure out a way to find the two objects furthest away from each other and use those as the start and end objects for the function.
That is it then.
John Martini
One way to get the objects furthest away from each other is to use parts of the previous scripts (you can merge them later, I don't have much time right now so I leave that part to you), like:
Again, to use it just evaluate it and then you can pass it whatever you like, e.g.
It selects the resulting nodes for you this time ;)
This is what I was looking for.
you'll have to make two objects as your start and end and the run the script on the selected objects. It is not a streamline thing just yet but I wanted to show you what i wrote as where i was going with this.
Make sure your start object is at 0,0,0
(
local EndObj = $end
local StartObj = $start
local userSel = $Sphere003
local averageVal = [0,0,0]
local userSel = selection as array
fn averagePos startVal endVal =
(
userSel = getCurrentSelection()
averageVal += (startVal.position + endVal.position) ; averageVal /= (userSel.count+1)
)
if userSel.count > 0 do
(
Val = averagePos StartObj EndObj
for i = 1 to selection.count do
(
Obj = selection[i]
print Val
Obj.position = [(Val.x*i),(Val.y*i),(Val.z*i)]
)
completeRedraw()
)
)
This is exactly the same as the alignAndDistribute2 function if passed the type:#evenly argument with the exception that here you have to specify one object extra (and have one object at [0,0,0] coordinates) and as you don't sort the objects, they're aligned not based on their positions but rather their positions in the selection array (i.e. you get random results depending on the way you select them. As for finding out both the "border" nodes, in some sitations it could work, but those would be quite special. You have to pick at least one object as the starting one - that's what I did. I'm not sure if you tried the function, be sure to do it and then we can discuss what you think is missing/not working as you imagined.
Here you go:
Pass it some objects, a line (to keep it simple, it has to have 2 knots and 1 spline to work as expected) and distribution type. When object will be "out of the range" of the line (i.e. somewhere else than the other objects), the sorting may give unexpected results, but for the situation on your pictures, it will work. PointLineProj function implementation comes from prettyPixel.
Example usage: alignAndDistribute (selection as array) my_line type:#evenly
Well, looking at it again, looks like I should learn to read first :) Anyway, if you want to use it for object collection without a line, use this version instead:
Pass it some border object (it's hard to find one programatically in many situations when some coordinates you'd like to test against are the same and so on) and the rest of the objects to be aligned. Now it should be roughly what you wanted in the beginning.