Selected Object in Python


#1

Hi all,

I’ve got this routine:

import rhinoscriptsyntax as rs

rs.GetObjects()
rs.InvertSelectedObjects()

Unfortunately, I don’t ghet the result I expected: whatever the objects I select with rs.GetObjects(), all objects are selected at the end of the script… Any idea why it does that?

Thank you!

JB


#2

GetObjects just gets the identifier of the object so you can later on use that identification to tell python what to do with what. GetObjects returns a list, and that list needs a name. So do something like this:

myObjects=rs.GetObjects("select objects")

Now you have to tell Python that these objects are to be selected. One way is adding this line:

rs.SelectObjects(myObjects)

If you look at the help file you will see that GetObject() has options to it, so it possible to select the objects directly after you have picked them, or even have Python accept preselected objects and add filters so you can only select meshes, curves and/or polysurfaces etc, and/or only select objects from another list.

Good luck.


(Alain Cormier) #3

Hi,
By default picked objects are not selected. Try this:

rs.GetObjects(select=True)

#4

Thank you very much!