That’s assigned to a variable obj
when I type obj is Rhino.DocObjects.ExtrusionObject
, I’m expecting that it would evaluate to True. But it’s not. I think I’m using the is
keyword wrong. Any help please?
Hi @Will_Wang,
How about this:
import clr
extrusion_obj = clr.Convert(obj, Rhino.DocObjects.ExtrusionObject)
if extrusion_obj:
# todo...
– Dale
What about
if isinstance(obj,Rhino.DocObjects.ExtrusionObject):
#do something
what makes the difference? looks like isinstance() is a built-in method. why wouldn’t is
work?
clr.Convert(obj,Rhino.DocObjects.ExtrusionObject)
would throw an error if the obj
isn’t that type, therefore stopping my script, which is essentially a type filter so a lot of non-type
As far as I know (my programming knowledge is not incredible) ‘is’ means that the argument is exactly the same object as the target - this from StackOverflow:
The operators
is
andis not
test for object identity:x is y
is true if and only ifx
andy
are the same object.
In this case your object is an instance of an extrusion object, not the equivalent of the class itself…
At least that’s the way I understood it, I just picked up ‘isinstance’ on the fly from looking at other examples…
Thanks! Very clear.
type(obj) is thetypeyoucomparewith