Problem using rhinoCommon to fillet breps

I uploaded two 3dm files in the posts below because a single example file with all objects was just too large (I think)…

I used RhinoCommon in a Grasshopper component to make some solid “cuboids”: 6 faced closed polysurfaces, with BrepSolidOrientation.Outward.

I checked in the Rhino UI, they look kosher.

I used this to try and fillet some edges.

private void FilletEdges(Brep[] cuboids, double radius, int[] edgeIndexes)
            double t = DocumentTolerance();

            double[] radii = new double[edgeIndexes.Length];
            for(int i = 0; i < radii.Length; ++i)
                radii[i] = radius;

            for(int i = 0; i < cuboids.Length; ++i)
                cuboids[i] = Brep.CreateFilletEdges(cuboids[i], edgeIndexes, radii, radii, BlendType.Blend, RailType.DistanceBetweenRails, t)[0];

Here is where I called it:

 Surface[] outrPatches = new Surface[] { outrCuboidParameters.subsetPatches.outrPatches[0] };
            Surface[] innrPatches = new Surface[] { innrCuboidParameters.subsetPatches.innrPatches[0] };
            Brep[] cuboids = MakeCuboids(
            AddTo(cuboids, C);
            FilletEdges(cuboids, 0.03, new int[] { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11 });
            //FilletEdges(cuboids, 0.03, new int[] { 0, 2, 5, 8 }); // just the straight edges that connect outr and innr patches
            AddTo(cuboids, B);

I initially just tried to fillet the edges that join my outer and inner patches (they are actually simple surfaces). I trimmed a generating surface using Surface.Trim


The Brep.CreateFilletEdges call creates about 30 invalid breps out of about 166 input breps.

I had already hand filleted 166 breps in the UI to see if the fillets were possible before I wrote the code to do it.

The hand fillets worked but filleting 166 breps by hand meant that I had to fillet ALL edges (not just the 4 that I really want to fillet) simply because it would be insanely difficult to only select the ones I wanted. To select all you just do a drag select.

So I tried to fillet all edges in code and it fails (about a 5th of the time) whilst filleting them in the Rhino UI works.

What is the UI doing to make things work? I am using DocumentTolerance().

Attempt to upload just the unfilleted cuboids.

RhinoCommonFilletProblem_UnfilletedCuboids.3dm (3.4 MB)

I assume that you can hand fillet the unfilleted cuboids yourself. The radius is 0.03 and the blend type is DistanceBetweenRails

Failed, RhinoCommon, fillets.

RhinoCommonFilletProblem_FailedFillets.3dm (15.6 MB)

I thought that my way of making geometry was deterministic, that all “cuboids” shared the same edge indexes.

I was wrong so I changed the code to enumerate all edges looking for linear ones and then I fillet those edges.

It now works. (For the 4 linear edges)

I’m still left wondering why the fillet fails when I try to fillet ALL edges in code but it works in the UI.