Python IsGroupEmpty


#1

rs.IsGroupEmtpy() seems to be always returning true with a valid group_name input. Fixes?


(Menno Deij - van Rijswijk) #2

This is the code being executed

def IsGroupEmpty(group_name):
    """Verifies that an existing group is empty, or contains no object members
    Parameters:
      group_name = the name of an existing group
    Returns:
      True or False if group_name exists
      None if group_name does not exist
    """
    if not isinstance(group_name, str): group_name = str(group_name)
    index = scriptcontext.doc.Groups.Find(group_name, True)
    if index<0: return scriptcontext.errorhandler()
    return scriptcontext.doc.Groups.GroupObjectCount(index)>0

(from https://github.com/mcneel/rhinopython/blob/master/scripts/rhinoscript/group.py)

My guess is that the last line give the error, but by all means verify that by yourself. An alternative is to do for the last line

return len(scriptcontext.doc.Groups.GroupMembers(index)) > 0

#3

Thanks, menno. Tried your suggestion with same results as before which led me to realize that the code is executing properly but that there is a semantic issue with the function; “IsGroupEmpty” should logically return true if the group is empty, and false if it is not. This implementation does the opposite so…

return not scriptcontext.doc.Groups.GroupObjectCount(index)>0

…produces the expected result.

Steve, if you’re listening how should I best go about reporting such an issue? On your git page?

edit: nevermind, the git page answered my question