Notifications
Clear all

[Closed] get name of a group

hi

I’m trying to get a name of a group, but when i’m using $.name when the group is selected max printing an error :
[size=1]– Unknown property: “name” in $selection[/size]

What is the difference between groups and any other objects?

6 Replies

The problem is the way that Max (and maxscript) handle groups. When you create a group you are actually creating an invisible dummy item. If you select a group, the current selection variable will hold that dummy and everything else inside the group. A quick way to find the name of the selected group could be:

(
   FOR obj in selection WHERE isGroupHead obj DO print obj.name
)

However if you have nested groups you will get more than one result…

Marco’s solution is definitely the most direct way to get the group head, as long as there are no groups nested within the group you want. (In that case, both group head names will print to the Listener window with no indication of which one is the top level head.) If this isn’t a problem in your case, use Marco’s example…there is no quicker way to do it.

However, if you’re interested in understanding more about dealing with groups, here are 2 threads discussing more advanced techniques for dealing with groups and group heads.

http://forums.cgsociety.org/showthread.php?f=98&t=355859
http://forums.cgsociety.org/showthread.php?f=98&t=442762

(Be warned that those discussions assume the use of variables to directly reference scene nodes/objects, rather than pathname literals. Pathname literals describes the shorthand style of maxscript such as “$” for a single selected object or “$Box01” for the first object found with that name. These are used very commonly for quick and dirty maxscript inside the listener window, but are not precise enough for more involved scripting. Truthfully, any script worth actually saving in an .ms script file should be using variable references.)

Thanks guys

The

(
FOR obj in selection WHERE isGroupHead obj DO print obj.name
)

has done it, but now i’ve ran into another unexpected problem-
After i parent the group to another object i can only select the group members and the group node is apperently hidden.
Should i find the gruopHead and parent it?
If so what is the way of doing it?

the group technically is just a helper that is parented to all items in it afaik
so the .parent parameter where it is of class helper should give you the “group”

and how to get group name with your method and not get only one result!

the group name is the name of the parent group helper object wich you can acces like usual by .name