Hi everybody,
I am trying to implement the use of a Sweep2 operation in a plugin that we are writing. When I do the operation while manually selecting the curves in Rhino, the operation gives a nice result:
In our plugin I first tried to use the Brep.CreateFromSweep() method, but that gave very unsatisfying results:
When using the SweepTwoRail class as is mentioned in the Brep.CreateFromSweep() documentation, I always get an empty Brep back.
Does anybody have any idea what I am doing wrong?
Here is the code that I use to test this functionality and the 3dm file with the actual curves :
allcurves.3dm (42.5 KB)
protected override Result RunCommand(RhinoDoc doc, Rhino.Commands.RunMode mode)
{
// Select Rail 1
GetObject go = new GetObject();
go.SetCommandPrompt("Select the first curve");
const ObjectType curveFilter = ObjectType.Curve;
go.GeometryFilter = curveFilter;
go.DisablePreSelect();
go.SubObjectSelect = false;
Curve rail1;
while (true)
{
GetResult res = go.Get();
if (res == GetResult.Nothing)
{
return Result.Failure;
}
else
{
rail1 = go.Object(0).Geometry() as Curve;
break;
}
}
// Select Rail 2
go = new GetObject();
go.SetCommandPrompt("Select the second curve");
go.GeometryFilter = curveFilter;
go.DisablePreSelect();
go.SubObjectSelect = false;
Curve rail2;
while (true)
{
GetResult res = go.Get();
if (res == GetResult.Nothing)
{
return Result.Failure;
}
else
{
rail2 = go.Object(0).Geometry() as Curve;
break;
}
}
// Select Guides
go = new GetObject();
go.SetCommandPrompt("Select the guiding curves");
go.GeometryFilter = curveFilter;
go.DisablePreSelect();
go.SubObjectSelect = false;
List<Curve> guidingCurves = new List<Curve>();
while (true)
{
GetResult res = go.Get();
if (res == GetResult.Nothing || res == GetResult.Cancel)
{
break;
}
else
{
foreach (ObjRef r in go.Objects())
{
guidingCurves.Add(r.Geometry() as Curve);
}
}
}
RhinoApp.WriteLine("Selected {0} guide curves",guidingCurves.Count());
// Do the Sweep with Brep.CreateFromSweep -> a result, but not helpful
Brep[] simple = Brep.CreateFromSweep(rail1, rail2, guidingCurves, true, doc.ModelAbsoluteTolerance);
foreach (Brep bb in simple)
{
doc.Objects.Add(bb);
}
// Do the Sweep2 with Sweep two rail -> no result
SweepTwoRail t = new SweepTwoRail();
t.ClosedSweep = true;
t.MaintainHeight = false;
t.AngleToleranceRadians = doc.ModelAngleToleranceRadians;
t.SweepTolerance = doc.ModelAbsoluteTolerance;
// This sweepSkirt is always empty
Brep[] sweepSkirt = t.PerformSweep(rail1, rail2, guidingCurves);
foreach (Brep bb in sweepSkirt)
{
doc.Objects.Add(bb);
}
// end
doc.Views.Redraw();
return Result.Success;
}