Messagebox if selection object is a group

Hi Guys,

As the Subject describes i'm trying to check if the selected object is a group or not. If it is then show a messagebox warning, if not then do something else. In the attached snippet I have simply shown another messagebox to warn "not a group". I have tried many variations and google searches but I cant seem to find the right answer, although I dont think I'm far away.

My test involved creating two boxes and grouping one of them, then select one at a time and run the script.

Any help would be very much appreciated. I have inlcuded my snippet of where I got too but getting stuck.

Thanks!

for obj in selection do
(
if (not isGroupHead obj == false) or isGroupMember == true then
(
messagebox("You selected a group")
)
else
(
messagebox("Not a group")
)
)

Comments

Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
pixamoon's picture

`

Hi,

If you want to check if there is any group object in multi selection, try this:

tmpArr = for o in selection where isGroupHead o collect o
 
if tmpArr.count > 0 then 
  messagebox("You selected a group")
else
  messagebox("Not a group")

Best,
Pixamoon

j_forrester's picture

Pixamoon, Thank you very much

Pixamoon, Thank you very much for the code snippet! Worked great.

and thanks also Miauu for the tip about checking if the group is open. I have ammended the for loop so it now reads tmpArr = for o in selection where isGroupHead o or isGroupMember o collect o which seams to work great. Unless you can see anything I have done wrong?

Thank you both very much!

miauu's picture

.

You can add a check for the open group head. :)

Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.