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


(IVELIN PEYCHEV) #1


(IVELIN PEYCHEV) #2

image


(IVELIN PEYCHEV) #3


(Steve Baer) #4

Use rs.filter.instance


#5

or just ‘4096’… :stuck_out_tongue_closed_eyes:


(IVELIN PEYCHEV) #6

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

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


#7

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)

(Steve Baer) #8

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.


(IVELIN PEYCHEV) #9

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.


#10

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:


(IVELIN PEYCHEV) #11

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


(Nathan 'jesterKing' Letwory) #12

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)

(IVELIN PEYCHEV) #13

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


(Nathan 'jesterKing' Letwory) #14

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


(IVELIN PEYCHEV) #15

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


(Nathan 'jesterKing' Letwory) #16

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


(IVELIN PEYCHEV) #17

Thanks :), that explains a lot.

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


(Graham) #18

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/


(IVELIN PEYCHEV) #19

Why is binary used, though?


#20

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

_
c.