[Closed] Objects Equal distance question ?
From left to right select four objects Result is correct. From right to left select is wrong ,More than four objects is too. Why ?
I want to every object max to next object min is Equal。
obj = for i in selection collect i
total = [0,0,0]
for i=2 to (obj.count-1) do (total += obj[i].max – obj[i].min)
format “Total X-size: %
” total[1]
format “Total Y-size: %
” total[2]
format “Total Z-size: %
” total[3]
posMax = obj[obj.count].min
posMin = obj[1].max
sp = (posMax-posMin-total)/(obj.count-1)
sp.x
for i=2 to (obj.count-1) do – loop (obj.count-2)
(
totalzong = [0,0,0]
totalzong += obj[i].max – obj[i].min –loop (obj.count-3)
format “Total X-size: %
” total[1]
format “Total Y-size: %
” total[2]
format “Total Z-size: %
” total[3]
obj[i].pos.x = posMin.x + sp.x * (i-1) + totalzong.x + (obj[i].max.x-obj[i].min.x )/2
)
This is the last:
obj = for i in selection collect i
total = [0,0,0]
for i=2 to (obj.count-1) do (total += obj[i].max – obj[i].min)
format “Total X-size: %
” total[1]
format “Total Y-size: %
” total[2]
format “Total Z-size: %
” total[3]
posMax = obj[obj.count].min
posMin = obj[1].max
sp = (posMax-posMin-total)/(obj.count-1)
sp.x
obj[2].pos.x = posMin.x + sp.x + (obj[2].max.x-obj[2].min.x )/2
for i=3 to (obj.count-1) do – (obj.count-2)
(
totalzong = [0,0,0]
totalzong += obj[i-1].max – obj[i-1].min – (obj.count-3)
format “Total X-size: %
” total[1]
format “Total Y-size: %
” total[2]
format “Total Z-size: %
” total[3]
obj[i].pos.x = posMin.x + sp.x * (i-1) + totalzong.x + (obj[i].max.x-obj[i].min.x )/2
)
It’s a bit hard to decode your question
About selection order, if you want a script working regardless of the user interaction, i.e. to leave him a freedom of using any selection manner, then… you’ll need a sort-algorithm using some property compatible with your task (like #name, #position, etc.).
This was discussed many times, so just search in the forum for “sort selection”.
And if I understand correct – you want to align, right? If so, lets presume (for simplification) you need to align your objects by Z axis, then you’ll need just 2 data values – object #pos.z and #max.z
here is an example:
-- #1. get selected objects:
myObjs = selection as array
-- #2. filter/collect (if needs)
-- #3. sort your array
-- #4. align:
oCount = myObjs.count
if oCount > 1 do ( -- as you start from 2, be sure are not out-of-bound
for i = 2 to oCount do (
myObjs[i].pos.z = myObjs[i-1].max.z
)
)
cheers!
Note: need to correct myself, as I simplified the axample too much, I presume the pivot is already is on #min.z but I hope you’ve got the idea and will finish that part