Notifications
Clear all

[Closed] Move to surface

hi guys,

am only a beginner at the scripting side of things so just thought id seek some help.

im just building on the move to surface script from the maxscript help file to work with groups.

The script works great for populating a terrain with houses or what not, but when i move a group, it seems to move the objects within the group, as apposed to the group as a whole, or will distort it in some way.

the script i got is as follows – any help would be greatly appreciated


clearlistener()
fn g_filter o = superclassof o == Geometryclass 
fn find_intersection z_node node_to_z =
(
local testRay = ray node_to_z.pos [0,0,-1 
local nodeMaxZ = z_node.max.z
testRay.pos.z = nodeMaxZ + 0.0001 * abs nodeMaxZ
intersectRay z_node testRay
)
 
rollout MoveTo_Rollout "Move to Terrain"
(
GroupBox grp_terrain "Select Terrain" pos:[14,10] width:140 height:38
pickbutton pb_terrain "Select" filter:g_filter pos:[18,25] width:132 height:20
Button b_height "Move to Terrain" width:100 height:20 offset:[0,10]
 
on pb_terrain picked obj do pb_terrain.text = obj.name 
on b_height pressed do
(
undo "MoveToSurface" on
(
disableSceneRedraw() 
for i in selection do
(
int_point = find_intersection pb_terrain.object i
if int_point != undefined then i.pos = int_point.pos 
) 
enableSceneRedraw()
) 
)
) 
 
if random_extrude_floater != undefined then (closerolloutfloater random_extrude_floater)
random_extrude_floater = newrolloutfloater "Extrude2Surface" 180 135
addrollout MoveTo_Rollout random_extrude_floater
 

2 Replies

When you do:

for i in selection do

You’re affecting each object in the selection which means each object in the group is evaluated separately. What you want to do is:

for i in selection where IsGroupHead i do

This will go through the selection and only affect the group heads, the dummy that you see when you open a group, moving the group as a whole.

thanks heaps for that, saved me a lot of time

cheers