Extract mesh holes in Rhino3dm

Dear McNeel,

Is it possible to extract inner naked (hole) lines, of a mesh via Rhino3dmNET library?
I would like to extract the blue colored lines:

I tried converting the mesh to a brep (Brep.CreateFromMesh), but without success. The mesh is successfully created to a brep, but then Brep.DuplicateNakedEdgeCurves simply threats both outer and hole naked edges as the same:

Running Brep.MergeCoplanarFaces before Brep.DuplicateNakedEdgeCurves - would solve the issue, but sadly that method does not exist in Rhino3dmNET.

At the moment, I am finding the longest naked polyline - and stating that: this is the outer one.
And all others are inner naked (hole) polylines.
I am an interested if there is another way, to extract the mesh holes? Maybe with a “topological” approach, instead of upper: longest polyline approach?

Attached is the mesh
holes.gh (22.1 KB)

Right, Brep.MergeCoplanarFaces is part of the Rhino Core which is not available in rhino3dm.

I am curious as to how you would do this within Rhino if you had all of the SDK tools available?

1 Like

Something like this should work in rhino3dm (thanks to @DavidRutten for the tip). You will have to decide how to filter out the outer edge loop.

        // mesh = your mesh
        var edges = new List<Curve>();
        
        for(int i = 0; i < mesh.TopologyEdges.Count; i ++ )
        {
            var faceCnt = mesh.TopologyEdges.GetConnectedFaces(i).Length;
            if(faceCnt == 1)
                edges.Add(mesh.TopologyEdges.EdgeLine(i).ToNurbsCurve());
        }

        var result = Curve.JoinCurves(edges);
1 Like

Hi @fraguada ,
Thank you very much for the detailed reply and your help.

I thought that calling Brep.MergeCoplanarFaces before Brep.DuplicateNakedEdgeCurves, would enable me to differentiate between the outer naked, and inner hole lines.
But now I see that this does not work, even in Rhino, without using Rhino3dm.
It seems that RhinoCommon threats the inner hole lines: as only those, whose trim curves are not intersecting the BrepFace outer trim curves:

This code:

# python
tol = 0.01
success = brep.MergeCoplanarFaces(tol)

if success:
    # outer naked lines
    outer = True
    inner = False
    outerNaked_L = brep.DuplicateNakedEdgeCurves(outer, inner)
    
    # inner (hole) lines
    outer = False
    inner = True
    hole_L = brep.DuplicateNakedEdgeCurves(outer, inner)

results in:

Of course, I always assume that: the longest joined curve in outerNaked_L is the outer one I need. While the other one in the same list - is a hole curve.

Thank you for this solution Luis. Indeed clever solution.
I was still puzzled that neither Brep nor Mesh RhinoCommmon objects having a method which can differentiate between an outer naked edge. And an inner naked edge (hole).

1 Like

For breps, look at the trims not the edges.

— Dale

2 Likes

Hi @dale ,
Thank you very much for the suggestion.

If I understood you correctly, I have to check if trim loop, is outer/inner type?

If this is so, I still can’t extract the biggest hole curve:

The following code:

brepLoops = brep.Loops
brepEdges = brep.Edges


hole_L = []

for brepLoop in brepLoops:
    if (brepLoop.LoopType == rg.BrepLoopType.Inner):
        for brepTrim in brepLoop.Trims:
            
            BEI = brepTrim.Edge.ComponentIndex().Index
            BE = brepEdges[BEI]
            BE_crv = BE.DuplicateCurve()
            hole_L.append( BE_crv )

Results in: