relative align a object set

hello everybody.i am working on a simple script but facing some

i usually group a couple of object, align the group to desired object and then ungroup there a simple way to do this, so that objects keep their previous arrangement. i like to use the selections average x,y and min z for align.
do i have to use the average center as working pivot?

if you know it ,please help me out. thanks


Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
zahidhasan's picture

thanks garp for posting the

thanks garp for posting the simple and beautiful solution.

Garp's picture

This maybe...

    rollout rltAlignSelToObj "Align Sel. to Object"
        pickButton pb "pick object to align to"
        on pb picked obj do (
            if (n = selection.count) != 0 do (
                local pos = [0, 0, 0]
                for o in selection do pos +=
                move selection ( - pos / n)
            destroyDialog rltAlignSelToObj
    createDialog rltAlignSelToObj
TsveTan's picture


Yes,that's right.
You can place three spinners in the rollout and control the scrolling through the weight alignment.
In my sample it shouuld be:
mypoint.position = [spn1*(minx + maxx), spn2*(miny + maxy),spn3*(minz+maxz)] , where
spn1,2,3 are the spinners x,y,z weight parameters: (0.01 ... 1.0) or to overweigh, the values may be >1.0.
values of 0.5 correspond with the x,y,z middle.

zahidhasan's picture

yep. that is mathematically

yep. that is mathematically right. but i was thinking kind of weighted automatic average .lets say you have four object at (-5,0,0) and one box at (5,0,0)position.
the group center is at (0,0,0)but the average center will be at

:-) there must be simple term like for this .something like center of mass.

TsveTan's picture


Hi , sorry for the late response.
You need to loop through all selected objects to find selection min x, max x,min y, max y and min z.
It will look something like:
global minxarray=#(),maxxarray=#(),\
minyarray=#(), maxyarray=#(), minzarray=#()
if selection.count != 0 do
For i = 1 to selection.count do
insertitem Selection[i].min.x minxarray (minxarray.count+1)
Insertitem Selection[i].max.x maxxarray (maxxarray.count+1)
Insertitem Selection[i].min.y minyarray
Insertitem Selection[i].max.y maxyarray (maxyarray.count+1)
Insertitem Selection[i].min.z minzarray
Minx = amin minxarray
Maxx = amax maxxarray
Miny = amin minyarray
Maxy = amax maxyarray
Minz = amin minzarray
--Then create the group group01
group selection
--and parent the group to a temporal point helper
mypoint = point()
mypoint.position = [(minx + maxx)/2, (miny + maxy)/2,minz]
$group01.parent = mypoint
-- align the helper
mypoint.pos = mydesiredobject.pos
delete mypoint
--and finally explode the group if needed
ungroup $group01
-- mydesiredobject is a variable that i have not defined yet. This is the goal object for alignment.
I think you need to create a roolout with a pickbutton and a button.By clicking the pickbutton pick the desired object. Then declare it with mydesiredobject = getnodebyname mypickbutton.text
By pressing the simple button execute the script that I have written. I think you should say the pickbutton control to show the picked object as text over it. See the pickbutton properties help topic.

zahidhasan's picture

thanks a lot man.i really

thanks a lot man.i really appreciate your detail reply.i gonna try it .
in the mean time i was using ".center ".it also works fine.

now i am thinking an weighted average center my be more suitable rather than only center.its possible by your method as you consider them each by each. :-)
thanks again.

Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.