I can see that PolyCurve() class has an Append() method. My question is does it only accept Line, Curve and Arc classes? I am trying to construct a PolyCurve from Lines, arcs and nurbscurves. Does anyone have an example of appending a Nurbs Curve to PolyCurve? I keep getting False as a result.
Well, a Rhino.Geometry.Curve
is an abstract class, and a Rhino.Geometry.NurbsCurve
inherits from Curve. So (basically) you can append any kind of curve.
Here is a cheap sample of how to build a polycurve:
protected override Result RunCommand(RhinoDoc doc, RunMode mode)
{
var go = new GetObject();
go.SetCommandPrompt("Select polycurve");
go.GeometryFilter = ObjectType.Curve;
go.SubObjectSelect = false;
go.Get();
if (go.CommandResult() != Result.Success)
return go.CommandResult();
var crv = go.Object(0).Curve();
if (null == crv)
return Result.Failure;
var polycrv = crv as PolyCurve;
if (null == polycrv)
{
RhinoApp.WriteLine("Not a polycurve");
return Result.Failure;
}
var pieces = polycrv.Explode();
var new_polycrv = new PolyCurve();
foreach (var piece in pieces)
new_polycrv.Append(piece);
if (new_polycrv.IsValid)
{
doc.Objects.AddCurve(new_polycrv);
doc.Views.Redraw();
}
return Result.Success;
}
Hi Dale,
Yes, this is very similar to what I have been trying to implement. What would be the reason that a PolyCurve would be invalid? After I append all my pieces to it, I checked it for IsValid and it returns False. Of course I am not building it by exploding and rebuilding it like you are showing but It was very much a valid curve in the past/other software (Dynamo).
This might help you figure out where the problem in your polycurve is:
string log;
if (new_polycrv.IsValidWithLog(out log))
{
doc.Objects.AddCurve(new_polycrv);
doc.Views.Redraw();
}
else
{
Rhino.UI.Dialogs.ShowTextDialog(log, EnglishName);
}
I should add that the Append
member doesn’t do a whole lot. So if you have a pile of unorganized and/or unorienteded curves, best to use Curve.JoinCurves
.
~ D
Will do, thank you,