Notifications
Clear all

[Closed] Unable to get group name?

After searching for a while I am still unable to find a way to get the currently selected group name. Since max just returns a list of objects in the group, $.name is invalid. I would just loop through to find the isGroupHead() but with nested groups, this is unreliable. I could do some trickery to find it but there has to be a simple way, right?

8 Replies

Groups are basically dummy objects… There are a couple of ways you can look for a group… if there is a better way than what I am telling you now someone will correct me for sure, but this is how I use it in one of my scripts…

 myGroups = for g in helpers where (isGroupmember g != True and classof g == Dummy) collect g
   for X in myGroups do print X.name 
    This should do the job... If you use g = Objects instead of helpers it will give you the same result... obviously here if you have a dummy which is not a part of any group it will still be included in the results. But you can easily add some code to filter out unwanted scene objects and then run this code.
    
    another way is what you mentioned>> isGrouphead. But i dont remember why i dont use it.

holy crap, well that was my noob moment for the day

I actually just need to use:


for n in helpers do (
	if n.isSelected == true then print n
)

it’s been a long day

That function would be problematic if you had a dummy in your group.

This is the function I use.

 
---- Find most senior group containing designated object ---
fn FindGroupHead obj = 
(
 if (isValidNode obj) then
 (
  try 
  (
   obj = (obj as array)[1]
  )
  catch()
   if ((isGroupHead obj)AND(not (isGroupMember obj)))
   then (return obj) 
   else (if (isGroupMember obj) then (FindGroupHead (obj.parent)) else (return undefined))
 )
 else
 (
  return undefined
 )
)


Also if you just want to search the current selection:

 
fn FindGroupHeadinSelection objs =
(
 for o in objs do
 (
  if (isgrouphead o) do return o
 )
)

The problem with the second function is if there is a neested group. You will dimply find the first group head which may not be the senior most grouphead. I’ll check out the first one you posted

Thanks

Yeah I hate the way max handles groups all around. The isgroupmember + parenting is a nightmare when you want a group parented to an object.

So say you have a hand group parented to an arm which is in a body group. Grrrr!

The problem with the first one is that it finds the most senior group. I suppose you could add a filter… and find the most senior selected parent head by modifying the first function.

P.S. Give Ely Cannon my regards if you ever run into him down there. Although I’m not sure which Blizzard he’s at.

This returns an array of the top most group(s) selected…


function ReturnTopSelectedGroups = (
local SelGroupHeads =#()
local tnGroupHeads = for SelObj in selection where (isgrouphead SelObj) collect SelObj
for SelObj in tnGroupHeads do
   if SelObj.parent == undefined then append SelGroupHeads SelObj
   else if SelObj.Parent.isSelected == false then append SelGroupHeads SelObj
SelGroupHeads
)

Of course as soon as you right something to work on one group, the artists want to select two or three thousand seven hundred and twenty three groups and do the same thing… hence the returned array… For a simple, single group closed and selected, just get the first item in the returned array.
As you can see it checks to see if it’s at the top of the node tree, hence no parent, or does NOT have a selected parent above it.

Just a side comment: whatever you do: don’t just grab (selection as array)[2] that works about 98% of the time and will lead you to a sense of false security. Speaking from experience here.