Is SelName buggy inside of commands and scripts?

A very helpful feature of Rhino is that you can use selection commands like _SelName from command line while other commands or scripts are waiting for objects to be selected. But since a few releases (6.1? - 6.21) the _SelName doesn’t work as intended.

Let’s assume that there are one or more objects named ‘a’ and one or more objects named ‘b’. ‘_SelName’ works fine outside of a command or script. What means if in selName-dialog you first click ‘a’ and then ‘b’ (without shift or ctrl pressed) only ‘b’-named objects will be selected after pressing OK.
BUT, inside of a command/script, both - ‘a’ AND ‘b’ will be selected.
And to make things even worse: If you swap the 'a’s and 'b’s a few times in the dialog the objects get selected multiple times. It seems that each time a name is selected from the list all related objects are appended to the list of objects which finally will be selected. Just run the script below:

import rhinoscriptsyntax as rs

def test():
   """Let's assume that your document has one object named 'a' and one 
   object named 'b'
   objs = rs.GetObjects('type in "selname" and swap the a and b named'+
                                     ' objects several times')
   if not objs:

   print('Number and names of selected objects:', 
           len(objs), [rs.ObjectName(obj) for obj in objs])

if __name__ == '__main__':

There are some older related topics:

but both address ‘only’ the rs.GetObjects function. The current bug affects pure rhino command line commands as well. So i assume that the SelName-dialog misbehaves.

Hello - do you want the user to use SelName, or do you want to select objects by name from the script and your making the user do it because you can use that command? Just making sure because
rs.ObjectsByName() may be useful…

At any rate I see the behavior you describe, I’ll see if that can be tuned up.
The behavior is the same in RhinoScript.

Many thanks for your response and for creating the bug report.

SelName is our weapon of choice to distinguish objects while using our (quite impressive :wink: ) rhino python framework. So this bug somehow jeopardize our traditional workflows.

Unfortunately rs.ObjectsByName() won’t help us because
a) it can’t be used interactively
b) sometimes we select the objects manually, by color, by layer, … Depends on the situation. But many thanks anyway.

To illustrate this bug i’ve uploaded a short video:

Get the names and put them in a listbox (from which the user can choose only one)…

Hi Helvetosaur,

Thanks for your suggestion, this is very much appreciated.

We thought about that as well. But with hardcoding this into our scripts we would loose the possibility to select objects by hand, layer, group, …

I also tried to implement your suggestion as a RhinoCommand, which worked well when called ‘standalone’. But the listbox dialog wont show up if the command is called while an other command/script is waiting for objects to be selected.
It also feels strange to (re)implement a basic rhino method which worked well over the last years.