I’m having an infuriating time! Can someone help?
I am doing a PerformSweepRebuild in c# - using code based on this chap
In the code I have taken a Rectangle in the CPlane, split it at the corners, rebuilt the LineCurves as Nurbs Curves (10 control points, degree 3). I’ve then set the control points so that they are fitted to the Z height of the data I am using.
If I save this Rhino model and run a new command that does the following - the PerformSweepRebuild works fine:
if (!Rhino.Geometry.Curve.DoDirectionsMatch(crosssection[0], crosssection[1]))
crosssection[1].Reverse();
Rhino.Geometry.SweepTwoRail sweep = new Rhino.Geometry.SweepTwoRail();
sweep.AngleToleranceRadians = doc.ModelAngleToleranceRadians;
sweep.ClosedSweep = rail1_crv.IsClosed & rail2_crv.IsClosed;
sweep.SweepTolerance = doc.ModelAbsoluteTolerance;
sweep.MaintainHeight = true;
var breplist = sweep.PerformSweepRebuild(rail1_crv, rail2_crv, crosssection, 5);
foreach (Brep brep in breplist)
{
foreach (BrepFace f in brep.Faces)
{
doc.Objects.AddBrep(f.DuplicateFace(false)); // duplicate face will create a separate brep of each face
}
}
return Rhino.Commands.Result.Success;
However, If I run it as a single command, so straight after I’ve set the Z height, I then go on to do the above PerformSweepRebuild, the command fails. I’ve looked hard for stupid mistakes - like selecting the wrong rails/cross sections and I’m sure that isn’t the problem. I also make sure the rail directions match in both cases.
This is the sample that doesn’t work - exactly the same code using exactly the same Nurbs Curves:
if (!Rhino.Geometry.Curve.DoDirectionsMatch(crv1, crv2))
crv2.Reverse();
if (crosssection.Count > 1)
{
if (!Rhino.Geometry.Curve.DoDirectionsMatch(crosssection[0], crosssection[1]))
crosssection[1].Reverse();
}
Rhino.Geometry.SweepTwoRail sweep = new Rhino.Geometry.SweepTwoRail();
sweep.AngleToleranceRadians = doc.ModelAngleToleranceRadians;
sweep.ClosedSweep = crv1.IsClosed & crv2.IsClosed;
sweep.SweepTolerance = doc.ModelAbsoluteTolerance;
sweep.MaintainHeight = true;
var breplist = sweep.PerformSweepRebuild(crv1, crv2, crosssection, 5);
Any ideas?? !