Python rhinoscriptsyntax SelectObjects() is slow

Hi,

The SelectObjects() method is slow, due to it calling SelectObject() which is redrawing the view after each selction.
Could this be optimized to only redraw after all are selected?

Thanks
-Willem

def SelectObjects(object_ids):
    """Selects one or more objects
    Parameters:
      object_ids = list of Guids identifying the objects to select
    Returns:
      number of selected objects
    """
    id = rhutil.coerceguid(object_ids, False)
    if id: object_ids = [id]
    rc = 0
    for id in object_ids:
        if SelectObject(id)==True: rc += 1
    return rc


def SelectObject(object_id):
    """Selects a single object
    Parameters:
      object_id = the identifier of the object to select
    Returns:
      True on success
    """
    rhobj = rhutil.coercerhinoobject(object_id, True, True)
    rhobj.Select(True)
    scriptcontext.doc.Views.Redraw()
    return True


Maybe something like this?

def SelectObjects(object_ids):
    """Selects one or more objects
    Parameters:
      object_ids = list of Guids identifying the objects to select
    Returns:
      number of selected objects
    """
    rhobjs=[rhutil.coercerhinoobject(id, True, True) for id in object_ids]
    rc=0
    for rhobj in rhobjs:
        if rhobj.Select(True): rc+=1
    scriptcontext.doc.Views.Redraw()
    return rc

With 10K objects this runs slightly slower than Ctrl+A - maybe three seconds as opposed to two. Significantly faster than the existing rs.SelectObjects which takes about 11 seconds. However, rc is returning twice the number of objects selected - in fact rhobj.Select(True) returns 2, when I thought it would return 1 (True)…

doesn’t work
rc+=rhobj.Select(True)

works
if rhobj.Select(True): rc+=1

–Mitch

1 Like

BUMP
@stevebaer?

-Willem

Hi. I’ll fix this:
http://mcneel.myjetbrains.com/youtrack/issue/RH-30088

Cheers,
Alain

2 Likes