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

image

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)

or

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.

Edit:
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:

image

Iā€™ll fix my stuff when you doā€¦ :stuck_out_tongue_winking_eye:

1 Like

:rofl:
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)
1 Like

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 & :

http://block.arch.ethz.ch/blog/2016/10/bitwise-operators-in-python/

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ā€¦

_
c.