Turn list consisting of Breps and Extrusion into list with only Breps

I feel like there should be an easier way to do this which is the reason for this topic.

I’m working on a command which will do some stuff to an object which can be a surface, polysurface or extrusion. I’ve set the geometryfilter to “ObjectType.Brep” which seems to make sure I can select all of these types.

var go = new GetObject();
go.GeometryFilter = ObjectType.Brep;

while (true)
        {            
            var res = go.GetMultiple(1,0);

            if (go.CommandResult() != Result.Success)
                     return Result.Failure;

            break;
         }
var objs = go.Objects();

Now afterwards I want to get a list of Breps so I can apply the same methods to these objects. But I can only know of a cumbersome way of doing it where I try to convert the geometry into the brep and if it doesn’t work try to convert the geometry to a extrusion to then convert to a brep.

var brlist = new List<Brep>();

foreach (var i in objs)
            {
                var brep = i.Object().Geometry as Brep;
                if (brep == null)
                {
                    var extr = i.Object().Geometry as Extrusion;
                    brep = extr.ToBrep();
                }
                brlist.Add(brep);
            }

Is there an easier/quicker way of doing this? Where I quickly get a list of Breps (since that is the geometry filter I am applying for selecting objects)

in RC you have tryconvertbrep
Brep.TryConvertBrep method (rhino3d.com)
This should work for you

Farouk

1 Like

Thanks! @farouk.serragedine