Notifications
Clear all

[Closed] Script to return group data?

Hi again all,

I’ve fingered through the maxscript reference and the closest i’ve seen to what i’m looking to do is the GroupBox function. unfortunately I think GroupBox is closer to what I want to do in it’s name than in it’s actual function.

I’m looking for advice (or code if neccesary) that could lead me in the direction of obtaining a Grouped object’s overall X Y Z pos and it’s Height Width and Depth. I’m assuming grouped objects can be identified by a rectangular boundary and was wondering if max retained that variable so I could obtain it somehow?

Thanks in advance to everyone.

5 Replies

It’s called “grouphead” the commands are isGroupHead and IsGrooupMember. For the overall size look around here for “bounding box”. There are a few threads explaining how to get it.

Check out this thread regarding a complete “FindGroupHead()” function:
http://forums.cgsociety.org/showthread.php?t=355859

The function will return undefined if an object is not part of a group, but it will return the group head if it is part of the group. The group head is an invisible dummy object that is the parent of all of the members of the group, and it is not directly accessible in the 3ds max interface. When you select the group in the interface, you’re actually selecting the group head. When you access the position and dimensions of the group head in Maxscript, it is actually giving you info regarding the group as a whole.

Here is a quick demo of the FindGroupHead function and some of the other Maxscript features you’ll need for what you’re doing. Run the script below in MAX, then read the code line by line and note the positions of the dummy objects in relation to the group.

(
resetmaxfile #noprompt

global FindGroupHead
fn FindGroupHead obj = 
 (
 if ((isGroupHead obj)AND(not (isGroupMember obj)))
 then (return obj) 
 else (if (isGroupMember obj) then (FindGroupHead (obj.parent)) else (return undefined))
 )
 
local MyBox = (Box name:"MyBox" pos:[50,50,0])
local MyTeapot = (Teapot name:"MyTeapot" pos:[-50,50,0])
local MyBall = (Sphere name:"MyBall" pos:[0,-50,0])
 
clearSelection()
select #(MyBox,MyTeapot,MyBall)
global MyGroup1 = group selection--THIS IS ONE WAY TO GET A DIRECT REFERENCE TO THE GROUP HEAD
global MyGroup2 = (FindGroupHead MyTeapot)--THIS IS THE OTHER WAY
 
print ("Group Head references are the same: "+((MyGroup1==MyGroup2) as string))
 
setGroupOpen MyGroup2 true; setGroupOpen MyGroup2 false--COMMENT THIS LINE TO SEE PROBLEM
 
format "Min:%, Max:%, Center:%
" (MyGroup2.min) (MyGroup2.max) (MyGroup2.center)
 
Dummy name:"min" pos:(MyGroup2.min)
Dummy name:"max" pos:(MyGroup2.max)
Dummy name:"center" pos:(MyGroup2.center)
Dummy name:"BackLeft" pos:[(MyGroup2.min.x),(MyGroup2.max.y),0]
Dummy name:"FrontRight" pos:[(MyGroup2.max.x),(MyGroup2.min.y),0]
select MyGroup2
)

FYI: There is a potential problem in which the group head sometimes doesn’t report the correct Min/Max positions until it is opened & closed, which seems to update this data on the group head. This problem is avoided in this script by the line using the setGroupOpen command twice. I suggest that you “comment” this line by putting 2 dashes in front of it and then running it again. That line will be ignored and you’ll see the dummy positions being quite wrong. I don’t know why this happens or why the fix works, but there you go.

Joel,

If you don’t want to learn any Maxscript, here is a Rollout Floater Window script that will give you what you asked for. Run it and press the button, then pick the group or a member of it either in the scene node list or the viewports. In the Maxscript Listener window, you will see the width/height/depth dimensions and the position/min/max/center locations.

(
global MyRolloutFloaterWindow
global FindGroupHead
fn FindGroupHead obj = 
(
if ((isGroupHead obj)AND(not (isGroupMember obj)))
then (return obj) 
else (if (isGroupMember obj) then (FindGroupHead (obj.parent)) else (return undefined))
)
rollout MyRollout "Find Group Info" 
(
pickbutton mypickbtn "Pick Group or Group Member"
on mypickbtn picked sel do 
(
local gruphead = (FindGroupHead sel)
if (gruphead!=undefined) then 
(
setGroupOpen gruphead true; setGroupOpen gruphead false
format "
%
" (gruphead.name)
format "Width:%
" (gruphead.max.x - gruphead.min.x)
format "Height:%
" (gruphead.max.z - gruphead.min.z)
format "Depth:%
" (gruphead.max.y - gruphead.min.y)
format "Pos:%
" (gruphead.pos)
format "Min:%
" (gruphead.min)
format "Max:%
" (gruphead.max)
format "Center:%
" (gruphead.center)
)
else (messagebox "Not a group or group member!" title:"Invalid Object!")
)
on MyRollout close do (MyRolloutFloaterWindow = undefined)
)
if (MyRolloutFloaterWindow!=undefined) do (closerolloutfloater MyRolloutFloaterWindow)
MyRolloutFloaterWindow = newRolloutFloater "My Rollout Floater Window" 300 64 
addRollout MyRollout MyRolloutFloaterWindow
)

My apologies to Joel and anyone else who tried the Rollout Floater code that I first posted. It was missing the FindGroupHead() function definition completely, and would crash after picking any object! I’ve since fixed the code in my previous post, and it works fine now.

Sorry for the totally noob mistake…I’m an idiot.

No problem John, I do want to learn max script and will go through the line by line example you posted.

thanks for you help!

edit: Ran the script and it worked smoothly. I will learn a lot from this – thanks again.