[Python] filtering blocks in rs.GetObject() missing


Use rs.filter.instance

1 Like

or just ‘4096’… :stuck_out_tongue_closed_eyes:

1 Like

Yeah, I saw this but it’s easier to remember the word :wink:

Thanks Steve. Who would’ve thought it’s an instance :smiley:

Not for me… plus when you want to combine several different types of filters, the lines get very long…

Say I want to limit my selection to surfaces, polysurfaces, meshes, and maybe let’s say blocks…

rs.GetObjects("Select your stuff", rs.filter.surface | rs.filter.polysurface | rs.filter.mesh | rs.filter.instance, preselect=True)


rs.GetObjects("Select your stuff", 8+16+32+4096, preselect=True)

I wouldn’t go that route as a general recommendation. When a named constant (or enum) is provided in a library it is best to use the name. The numbers are a hold over from RhinoScript and make the script difficult to read.

Ever heard of the psychological test where words are written in different colors , but the color doesn’t correspond to the actual color of that word.

Human brain works associatively. I don’t work solely with Rhino, nor program solely with Python. If the number is different the whole process becomes slower and difficult to switch from one to another. Also the code, however short, becomes difficult to read by someone not familiar enough with the numbers.

Perhaps. That is the argument that is always put forth. However, I always assume that people who are delving into rhinoscripting will quickly become familiar with this stuff; and it’s not too hard to look up in the help either.

And just to add a little spice to this conversation - the advice to spell everything out because it makes the script easier to read is brought to you by the same people who put together these types of examples:


I’ll fix my stuff when you do… :stuck_out_tongue_winking_eye:

1 Like

And I thought I’m nagging a bit too much.

Collect them into a variable that tells you what you want, then use that

thestuf = rs.filter.surface | rs.filter.polysurface
thestuff = thestuf | rs.filter.mesh # or thestuff = rs.filter.mesh | thestuff, if you like to have The Goods first...
thestuff = thestuff | rs.filter.instance

rs.GetObjects("Whaddayawant?", thestuff, preselect=True)

Why do you use this symbol?
What is the difference to when “+” is used?

You can use plus as well in this case, but I use the pipe symbol because you are OR’ing the values.

So if the first object is a surface then all subsequent selections will be surfaces? I do not get the OR here.

The numbers you posted in [Python] filtering blocks in rs.GetObject() missing (post 3) are numbers that follow the binary system. OR’ing binary numbers like that is like adding them together

01 | 10 = 11 -> 01 + 10 = 11 -> 1 + 2 = 3

1 Like

Thanks :), that explains a lot.

I guess I would’ve known this if I was a C/Cpp developer :stuck_out_tongue_closed_eyes:

See a more complete explanation here but with typos in the ‘or’ section, where | becomes & :


1 Like

Why is binary used, though?

yup, and filter is a reserved method name in python which should not be used as object name…