GetObjects / GetObjectsEx

Using Python Script. When I use GetObjects or GetObjectsEx is there a way to determine if the user selected multiple objects vs the user selecting one object that is a group of objects? If not, is there another way to get the user to select objects that would tell me if the user selected multiple objects vs a group that contains multiple objects?

you can iterate through the objects and see if they belong to a group

1 Like

@Will_Wang - Please see the following file and code:

First select a group:

  1. Run the code in
  2. Select the curve. It will also select the vertical line since it’s in a group.
  3. Press Enter.

You will receive the following GUID’s back. The one ending in 6f4 is the curve.

Now, select individual objects:

  1. Run the code in
  2. Select the curve only without selecting the group by using Ctrl-Shift.
  3. Then select the horizontal line.
  4. Press Enter.

You will receive the following GUID’s back.

How do I tell if the user selected a group vs an individual objects?
GetObjects.3dm (37.4 KB) (283 Bytes)

Hi Mike - rs.GetObjects() will return a list if Ids - len(listOfIds) will tell you how many in the list… does that do it?

grp = rs.GetObjectsEx("Select a group of objects.", preselect=True)
print (str(len(grp)) + ' objects were selected.')


iterate through all the returned guids, if any of them is in a group, get all the guids of that group and compared to the rest of the selected. if all of the group members are in the return guids, chances are that the user simply selected a group. otherwise it’d be your second scenario.

there’s an occasion where the user actually ctrl+shift+clicked all the individual members of a group. in that case my method would give you false result. but i think it’s gonna be very rare…

another thought is that you may try to do a keystroke track with an event listener

@Will_Wang - Ya good idea. I was hoping RS had a faster way. Thanks for the info.

@pascal @Will_Wang - I have created a method that iterates through the objects returned by rs.GetObjects and figures out which ones belong to a group entirely and then splits the list of objects into objects that don’t belong to groups entirely and objects that do. With the ones that do, the groups are returned.

This way you can get the objects back from rs.GetObjects, perform any copy and manipulate the copied objects, and then easily group the new objects into groups that are the same grouping as the originally selected objects.

See the attached files. Run the code and select a combination of any of the objects. The code will create new objects that are 50 feet above the original objects and then group the new objects in the same manner as the original objects.

Code like this can be useful if a developer is trying to create new objects and group them similarly to the groups that the selected objects are grouped by. It might be beneficial to have a new command added to Rhino 8 scripting that does this or an additional set of options so that rs.GetObjects and rs.GetObjectsEx returns the individual items and also the groups.

GetObjects.3dm (45.9 KB) (3.0 KB)