_SelName from rs.GetObjects not returning expected results

Hi all,
I wrote a rhinopython script where I use rs.GetObjects:

import rhinoscriptsyntax as rs
Obj_Ids=rs.GetObjects(message=“Select objects”,filter=0)
[…] other stuff

During testing, when I’m asked to select objects, for ease of selection, I want to have the possibility of using _SelName.
I tried, and _SelName pops the window up with objects’ names. However, when I select object by names from the window coming from _SelName, the output to the list Obj_Ids if often not correct.

In some cases objects ids appears twice. In some other cases I get ids of object which should not be in the list of selected objects, and they seems to be there only because they have a name which was temporarily clicked in the _selname window (right click, or shift+right click, or ctrl+right click), but which was not selected finally. Duplicated ids would not be a big issue. But in some cases objects are selected which have a name not selected in the window from _selname.

Note that direct selection of objects from the drawing, works perfectly. So the issue seems to be in the use of _selname.

The following script can be used to make a check:

import rhinoscriptsyntax as rs
ObjIds=rs.GetObjects(message=“Select objects”,filter=0)
print(“Number of ids %d” % len(ObjIds))
print(“Number of unique ids %d” % len(list(set(ObjIds))))

Am I doing something wrong, or is there actually something not working when calling _selname after rs.GetObjects ?


Hi Gabriele,

Not sure I understand what you want to do.
But if you are looking for an id of a certain Rhino object based on its name, you can use the rs.ObjectsByName() function:

name = rs.GetString("objects of what name do you want?")
ids = rs.ObjectsByName(name, True)
print ids

Hi djordje,
thanks for the reply.
I’d like to use _selname because, out-of-the-box, it opens up a window from which the user can select the objects’ names from the names of all objects, allowing also multiple selections.

Using ObjectsByName, it is necessary to ask the user the name of the object(s) (which the user might not know).

I would prefer the user to be able to select objects’ names from a window, with the possibility of multiple selections, in order to avoid the need for the user to remember the objects’ names. However, from rhinopython, without using selname, I have a couple of issues, because:

  • I cannot find a rhinopython command returning the names of all objects. It is possible to get the names of all active objects by selecting all active objects, getting the names of all selected objects, and unselect them, but it seems to me strange that I cannot find something like rs.ObjectsName (like rs.LayerNames) for returning the names of all the (active/nonactive) objects in the document…

  • MultiListBox seems to be not yet implemented. So it is not clear to me how can I have a ListBox with multiple selections (without going through using CheckListBox, which is a possibility, but not very convenient for this purpose);

Regarding the specific issue with _selnname, the problem is that, when using _selname from within a rs.GetObects prompt, the objects ids returned by selname basically do not always correspond to the actually selected objects if the user, in the list window opened up by selname, selects and then unselect some objects, or when the user perform a multiple selection with CTRL+ or SHIFT+ right click. Things usually go well only if there is a single selection from the list with a single mouse click.


Yes, you are correct: there is no something like rs.ObjectsNames (the way there is rs.LayerNames). Now that I think of it, it does sound useful.
And for sure, the MultiListBox is a useful function to be implemented. Maybe you could open a new issue on this function, requiring it to have the wrapper be made for next releases of Rhino.

Issue on rs.GetObjects not returning the correct ids is interesting. I have not had experience with it. Maybe you could report it as a bug too.
But before that, is this a somewhat similar code you are using? :

import rhinoscriptsyntax as rs

rs.Command("_SelName ")   # choose one or multiple Names

ids = rs.GetObjects("",preselect=True)
print ids

I have just used the ids (from rs.GetObjects() ) along with SelID command, and they work perfectly. For example:

import rhinoscriptsyntax as rs

rs.Command("_SelName ")   # choose one or multiple Names

ids = rs.GetObjects("",preselect=True)
print ids

for id in ids:
    rs.ObjectColor(id, [255,0,0])

Colors correctly all the objects with selected names to red.

Hi djorje,
in reality I actually do the opposite of what you are doing.
You first issue a _SelName, and then you call rs.GetObjects allowing for preselection of objects.

In my case, I firstly call rs.GetObjects. Then, after the selection prompt appear, I call _SelName directly from the prompt. This open up the selection window, from which I can select the names of the objects…

The way I do it, is, unfortunately, not working :frowning: