rs.IsGroup appears to require the group name (not the object name) in order to verify that an object is a group… or at least it seems. But… if I get as far as getting to the group name doesn’t that mean I’ve already verified that the object is a group? And if the code required such it would have crashed prior.
Long day so I’m sure I’m missing something obvious. Any help is appreciated!!
You’re right, the group names can also be found in other ways, e.g. rs.ObjectGroups
. If so there’s no pressing need to test them again (unless in an async situation, there’s an edge case when something else in that tiny intervening time interval deletes the group).
If you only have a string though, rs.IsGroup
tests candidate group names, not candidate objects. If you’re coding LBYL style, after rs.IsGroup(name)
returns True, you can then safely use e.g. rs.AddObjectToGroup
with name
. This is quite nice, as it’s straightforward to support passing group names between multiple Python components just the same as passing guids (using different args, or with a bit of extra code to distinguish between the two).
I’m not sure groups in Rhino even have a guid. Aren’t they implemented just as strings that can be added as tags to other objects, that are then interpreted as being members of the group of that name? I’ve previosuly wondered why the rhinoscriptsyntax functions all use a plain string as a handle, when so much else in the Rhino and Grasshopper APIs are implemented with special classes.
1 Like