ScriptSpot

Forum topic · General Scripting

Messagebox if selection object is a group

By j_forrester · 2017-06-28

Description

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 (3)

`

pixamoon · 2017-07-03

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

.

miauu · 2017-07-03

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

j_forrester · 2017-07-03

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!