Unexpected Sweep1 Result

Hello, Community
I’m trying to make a Custom GH Plugin using C#. I needed to use the CreateFromSweep method but in the end, I got unexpected Geometry(see the attached pics). I have tried every possible reason behind the glitch ( checked profile and rail curve intersections, curve continuity, seams adjustment, and changed tolerance of the CreateFromSweep method ) but nothing worked out.
I have no idea what I’m doing wrong.
Please, can someone help me how to figure out what is happening? Since we have no access to check how the native Grasshopper sweep1 component works, please, advise me where to start, and what resources can be useful in this case.
Thank you in advance.



Looks like the automatic crease splitter isn’t being used when the Sweep is created…

You might need to run this after the brep is created:

https://developer.rhino3d.com/api/rhinocommon/rhino.geometry.collections.brepfacelist/splitkinkyfaces

I also see from your notes you converted the rectangle to a NURBS curve - I’m not sure it will make a difference, but does anything change you convert it to a PolylineCurve instead?

Edit:
By the way, outside of GH, if I run the following code in a rectangular profile and a degree 3 NURBS curve, I get a normal 4 face polysurface.

import rhinoscriptsyntax as rs
import scriptcontext as sc
import Rhino

rail=rs.GetObject("Select rail",4)
prof=rs.GetObject("Select profile",4)

r_crv=rs.coercecurve(rail)
p_crv=rs.coercecurve(prof)

tol=sc.doc.ModelAbsoluteTolerance
sweep_result=Rhino.Geometry.Brep.CreateFromSweep(r_crv,p_crv,False,tol)
if sweep_result:
    for brep in sweep_result:
        sc.doc.Objects.AddBrep(brep)
    sc.doc.Views.Redraw()

RC-Sweep1.3dm (2.7 MB)

Edit 2:

Very interesting!!! If I run it in GH, I get the same result - one untrimmed surface

Yep, need to run the kink splitter.

1 Like

That should solve it

  private void RunScript(IList<Curve> Profile, Curve Rail, ref object Sweep)
  {
    // Write your logic here
    var tol = RhinoDoc.ActiveDoc.ModelAbsoluteTolerance;
    var brep = Brep.CreateFromSweep (Rail, Profile, false, tol);
    //another sweep method
    //var sweep = new Rhino.Geometry.SweepOneRail();
    //var brep = sweep.PerformSweep( Rail, Profile);

    //here you split the kinky faces. 
    for (int i = 0; i< brep.Length; i++){
        brep[i].Faces.SplitKinkyFaces();
    }
    Sweep = brep;
  }

edit: you can have a sanity check and see if the split kinky faces produces the same result as a regular gh sweep1. The cull duplicate curves recognizes that the interior edges of the GHSweep1 are identical to the ones from the C#Script output

IMO, this is a bug in the GH execution of Sweep - Rhino should not normally produce kinked faces unless it is specifically requested. And note that running it just in Python outside of GH does indeed split the faces at the kinks.

I fully agree

Thank You very much, Helvetosaur, Adel
The splitKinkyFaces () method worked for me…However, I’m not sure if it will work on more complex geometric figures…
Anyway, I already know what the reason was behind the issue. Thank you very much, I appreciate your help.

1 Like

I’m curious to know too. If you find anything during your tests, do let us know

I made a YouTrack item for this to be looked at.
https://mcneel.myjetbrains.com/youtrack/issue/RH-81305/RhinoCommon-CreateSweep-creates-kinked-surfaces-in-GH

Hello Adel, Helvetosaur
Sorry to bother you with the same question, but “SplitKinkyFaces” method did not work in this case. I’m trying to create a Rectangle3d in C#, fillet it, extrude and cap, but I’m facing the same issue we discussed above((.
Is there any tangible way to maintain kinks of filleted curve? I think if filleted curve retains those kinks, we will get a normal Brep with 24 edges.
Thanks.

Hi @Bakuri_Gogua
Soory for not seeing this sooner. Use the @ sign mention someone do they get notified.

Anyway, in your script, you’re converting your rectangle to a nurbs.

Instead, convert it to a polyline
ToPolyline()

Hello @adel.albloushi, thank you for your response.
I have converted the rectangle to a Polyline, but the RhinoCommon “CreateFilletCornersCurve”- method does not accept that polyline rectangle, since it takes a curve as the first argument. So I could not fillet the corners of the polyline rectangle ((

sorry i meant polylinecurve

After you fillet you also need to convert the result into a polycurve that you’d explode, or somehow explode into segments.

If that fails, maybe try filleting each two segments with trim option

make a loop where you extrude each segment, then you create a brep that joins all the extruded segments. Finally, you cap the brep

@adel.albloushi
I know I have bored you a lot with my questions, my apologies. Direct conversion from Rectangle to PolylineCyrve is not possible, so I have done it this way: first converted Rectangle3d (in my case rect1) to Polyline, then converted to PolylineCurve
1st: Polyline poly = rect1.ToPolyline();
2nd: PolylineCurve rectCrv = new PolylineCurve(poly);
Am I going the right way up to this point?
Even though, I am doing it right, how can I explode the resulting filleted curve? I could not find any method that explodes Curve or PolylineCurve…(((

here’s a script that does exactly what you want, following the logic i explained above

  
  private void RunScript(Rectangle3d x, ref object a)
  {
    // Write your logic here
    //get tolerances
    var tol = Rhino.RhinoDoc.ActiveDoc.ModelAbsoluteTolerance;
    //convert rectangle to polylienCurve
    var polyCurve = x.ToPolyline().ToPolylineCurve();
    //make fillet and cast it to polycurve
    var filletedCurve = (PolyCurve) PolyCurve.CreateFilletCornersCurve(polyCurve, 1, tol, tol);
    //explode the resulting fillet
    var filletedCurveExploded = filletedCurve.Explode();
    //create an empty list of breps
    var surfaces = new List<Brep>();
    //extrude each curve segment and add it to the list of breps
    foreach (var seg in filletedCurveExploded)
    {
        var srf = Surface.CreateExtrusion(seg, Vector3d.ZAxis*10);
        if (srf.HasBrepForm){
            surfaces.Add(srf.ToBrep());
        }
        
    }
    //try to join breps
    var surfacesJoined = Brep.JoinBreps (surfaces, tol);
    //try to cap joined breps
    var cappedBreps = new List <Brep>();
    foreach (var brep in surfacesJoined)
    {
        cappedBreps.Add(brep.CapPlanarHoles(tol));
    }
    
    //return result
    a = cappedBreps;
  }


1 Like

@adel.albloushi ,
Thank you very much for your patience and help. The code you provided was the solution. I am most grateful for your help. :pray: :pray: :pray:

1 Like