Hi,
I want to remove edges from breps.
Basically it is the same principle like in “Untrim”, only I want to process stuff further in this command.
GetObject go = new GetObject();
go.SetCommandPrompt("Pick edges of brep");
go.GeometryFilter = ObjectType.BrepLoop;
go.GeometryAttributeFilter = GeometryAttributeFilter.InnerLoop;
This is how I started, giving me the desired result, only being able to pick closed curves on a brep that are on the inside.
But now, when I want to remove them from the brep, it requires the brep’s loop’s component index.
I can retrieve the CI of an edge, but now I am stuck how to get the edges’s loop.
foreach (var obj in go.Objects())
{
Brep brep = obj.Brep();
BrepEdge edge = obj.Edge();
ComponentIndex[] cis = new ComponentIndex[] { edge.ComponentIndex() };
brep = brep.RemoveHoles(cis, Rhino.RhinoDoc.ActiveDoc.ModelAbsoluteTolerance));
}
The brep returned is null now, using the edge’s CI.
The documentation clearly asks for the loop, but how am I able to find the edge’s loop?
Thanks,
T.
Hi @tobias.stoltmann,
How about a different approach? If you want to perform changes based on the inner trim, you can still extract the OG inner curve, perform any operation on the inner curve and then apply it to the new recreated brep.
var newBreps = new List<Brep>();
foreach (var face in brep.Faces)
{
var outerLoop = face.OuterLoop;
if (outerLoop == null)
continue;
// Extract the outer boundary curve of the face
var outerCurve = outerLoop.To3dCurve();
if (outerCurve == null)
continue;
// Create a new face from the outer boundary curve
var newFaceBreps = Brep.CreatePlanarBreps(new Curve[] { outerCurve }, doc.ModelAbsoluteTolerance);
if (newFaceBreps != null && newFaceBreps.Length > 0)
{
newBreps.AddRange(newFaceBreps);
}
}
var finalBreps = Brep.JoinBreps(newBreps, doc.ModelAbsoluteTolerance);
if (finalBreps == null || finalBreps.Length == 0)
return Result.Failure;
Farouk
Hi @farouk.serragedine ,
thanks for the reply first of all.
Good approach, but what if I have multiple cutouts in the brep I want to remove just the one I picked?
Hi @tobias.stoltmann ,
Step1:
a)Proximity selection : We get the inner loop close to where the user clicked
b)Edge selection : We get the selected user edge
Step2:
Proceed with our script as is and as output you get newBrep with is clean.
Step3:
reapply all cuts except the selected inner curve
You can also customize the selected inner curve before applying the cut to the newBrep
Hope this sparks some ideas,
Farouk
1 Like
Thanks @farouk.serragedine, this is how I will do it!
Hi,
there remains a problem I deteced while trying to get the solution.
var cull = new List<BrepLoop>();
foreach (var edge in edges)
{
// This is a method I wrote to get a curve's closest object
// I checked the result and it works
int loopIndex = new CurveClosest(edge, brep.Loops).ClosestIndex;
cull.Add(brep.Loops[loopIndex]);
}
Brep newBrep = brep.RemoveHoles(cull.Select(x => x.ComponentIndex()).ToList(), Rhino.RhinoDoc.ActiveDoc.ModelAbsoluteTolerance);
Rhino.RhinoDoc.ActiveDoc.Objects.Add(newBrep);
Trying this, the brep does not change.
If I try to do it with a list of all BrepLoops
on the brep it works and removes everything.
cull = brep.Loops.ToList();
Do I use the method wrongly or… is it simply not possible to remove particular loops of breps?
Thanks,
T.