I wrote a quick function to move a couple of objects to the bottom right quadrant whilst keeping their relative positions. I thought the best way to do this would be to group and ungroup them - I noticed this is what happens when you merge a max file into your current scene. The problem I'm having is that it doesn't have the effect that I'm expecting.
If I call the function the objects are placed centrally, not in the quadrant. However if I type the script line by line in the listener it works flawlessly. Maybe I'm missing something?
fn MoveQuadrant = (
if selection.count > 1 then
(
group selection name:"tempGroup"
select $tempGroup
-- Center object
move $tempGroup [-($tempGroup.pos.x),-($tempGroup.pos.y),-($tempGroup.pos.z)]
-- Move to correct max quadrant
move $tempGroup [($tempGroup.max.x),-($tempGroup.max.y),-($tempGroup.min.z)]
clearSelection()
ungroup $tempGroup
)
else
(
-- Put Pivot on bottom of object
$.pivot = [($.max.x+$.min.x)/2, ($.max.y+$.min.y)/2, $.min.z]
-- Center object
move $ [-($.pos.x),-($.pos.y),-($.pos.z)]
-- Move to correct max quadrant
move $ [($.max.x),-($.max.y),0]
)
Replies
Thanks, that moves them all together by 20,20,0 but it doesn't position them in the lower right quadrant which is what I was trying to achieve. To do that I was taking the min and max values of the group and using that amount to work out where to move it to. Does that make sense?
groupedObjects = group selection name:"tempGroup"
--select group
select groupedObjects
--now work with $ as selection
--get the min and max values of the bounding box and apply to variable as Point3
BoundingBoxObjects = [$.max.x - $.min.x,$.max.y - $.min.y,$.max.z - $.min.z]
--set new position already with the proper offset to the bottom right quadrant
$.pos = [BoundingBoxObjects[1]/2,-BoundingBoxObjects[2]/2,0]
--ungroup object
ungroup groupedObjects
i don't consider the z value, but you can position on the ground plane with
BoundingBoxObjects[3]/2
means the half of the bounding box height is the right position for the group. With this method i got an issue with objects smaller then 0.02m in height (3dsmax 2010, system units meters) although the listener shows the correct values there are internal roundings (almost mystical ). See also Bobo's answer to float precision. If you have not such thin plates, it should be no problem.
In the end I decided to try a different approach, decided to move away from the grouping the objects and went with this instead which is probably slower way of doing it with the arrays. But it does seem to work well.
MOVE THE SELECTION
OR ONLY MOVE GEOMETRY CLASS
That's amazingly simple! Brilliant! The pivot thing was an addition. I'm still learning at max script so far I think I can get things to work but not necessarily in the fastest or most efficient way. Thanks for the help guys