Best method to loop through Objects to find out what type they are?

I am creating a command to allow user to select a bunch of objects on a plane.

My question is how do I loop through the list of objects as there are many types. At the start, I may just want to handle only Curve and TextEntity.

I use GetObject function to get any objects.

But what I find is do I use the GetType() and compare the type of Object.

Is there a smarter way of looping through the list of Geometry?

GetResult result = go.GetMultiple(1, -1);

         for (int i = 0; i < go.ObjectCount; i++)
         {
            // Check the type of the Object and process differently

            GeometryBase geo = go.Object(i).Geometry();


            geoList.Add(geo);

         }


         foreach (GeometryBase g in geoList)
         {
            if(g.GetType().Equals(typeof(PolyCurve)))
            {
               System.Windows.Forms.MessageBox.Show("PolyCurve");
            }
            else if(g.GetType().Equals(typeof(Curve)))
            {
               System.Windows.Forms.MessageBox.Show("Curve");
            }
            else if(g.GetType().Equals(typeof(TextEntity)))
            {
               System.Windows.Forms.MessageBox.Show("TextEntity");
            }
           

         }

You could use the GeometryFilter to restrict the getter to the types of objects you want the user to select: http://developer.rhino3d.com/api/RhinoCommon/html/P_Rhino_Input_Custom_GetObject_GeometryFilter.htm

@fraguada I understand the geometry filter. My question is more on how do I loop through all the objects and process them.

The question I had was how do I loop through them easily, because when you get object, you don’t know what type it is .

Just for an example, a Curve can be an Arc, an circle, etc.

Hi @TobyLai,

For objects that inherit from GeometryBase, you can use the typeof keyword that you are already using, or query the GeometryBase.ObjectType property.

For testing for curve types, it gets a bit more complicated. Here is an example you might find helpful.

https://github.com/mcneel/rhino-developer-samples/blob/6/rhinocommon/cs/SampleCsCommands/SampleCsClassifyCurve.cs

– Dale

Thanks @dale that is exactly what I am looking for.