Intercept Specific Objects

Hi All,

    for selectable_object in selectable_objects:

selectable_objects is a list of objects

if selectable_object.GetType() == ObjectType.Curve: print “OK”

(the example above is not good)

print selectable_object.GetType() output: Rhino.DocObjects.CurveObject
print ObjectType.Curve.GetType() output: Rhino.DocObjects.ObjectType
print ObjectType.Curve output: Curve

when the for loop is executed, i would like to know that object what type it is “curve type or whatever”

ps without using rhinoscriptsyntax

thanks.

Hello,

This is a simple example of how it was done in GH.
There may be a better way to do it.


IsCurve.gh (17.4 KB)

1 Like

Thats how you do it using RhinoCommon sdk and python

# check if the object is a curve
if curve.IsCurve:
    print("This is a curve")
else:
    print("This is not a curve")

Thats how you do it without using Rhinocommon SDK

for selectable_object in selectable_objects:
    if isinstance(selectable_object, Rhino.Geometry.Curve):
        print("The object is a curve")
    else:
        print("The object is not a curve")

The isinstance function returns True if the object is an instance of the specified class or of a subclass of the specified class, and False otherwise. In this case, if selectable_object is an instance of Rhino.Geometry.Curve or a subclass of Rhino.Geometry.Curve , the code will print “The object is a curve”.

1 Like

thanks @11159 @farouk.serragedine for reply

the Gh file might be useful to me in the future :+1:

this method crashes my code

with the second method I get the same message for all objects

“The object is not a curve”

in the same loop inserting rs.IsCurve returns True if it is a curve

if I send a loop print for each object, this description comes back to me

CurveObject: (unnamed) (0)
PointObject: (unnamed) (0)

where am i wrong?

for selectable_object in selectable_objects:
    if isinstance(selectable_object, CurveObject): #*CurveObject
        print("The object is a curve")
    else:
        print("The object is not a curve")

*CurveObject

it seems to work like this