[CommandMethod("drawPlineTest")]
public void drawpline()
{
double[] dangle = { 147.27, 218.65, 54.49, 120.02, 300.87, 64.39, 66.02 };
double[] dline = { 11.96, 8.16, 29.09, 22.93, 5.64, 17.06, 39.6 };
var doc = Application.DocumentManager.MdiActiveDocument;
var ed = doc.Editor;
PromptPointOptions inspoint
= new PromptPointOptions
("\nSpecify insertion point : "); PromptPointResult presult = ed.GetPoint(inspoint);
Point2d p1
= new Point2d
(presult
.Value.X, presult
.Value.Y); Polyline poly2
= new Polyline
(); poly2.AddVertexAt(0, p1, 0, 0, 0);
Point2d nextPt = Point2d.Origin;
var lastDir = double.NaN; ;
for (int i = 0; i < dangle.Count(); i++)
{
var ang = dangle[i] * Math.PI / 180.0;
if (nextPt == Point2d.Origin)
{
nextPt = GetPolarPoint(p1, ang, dline[i]);
lastDir = ang;
}
else
{
try
{
lastDir = lastDir - Math.PI + (dangle[i] * Math.PI / 180.0);
nextPt = GetPolarPoint(nextPt, lastDir, dline[i]);
}
catch { }
}
poly2.AddVertexAt(i + 1, nextPt, 0, 0, 0);
}
poly2.Closed = true;
using (Transaction trans = doc.Database.TransactionManager.StartTransaction())
{
var bt = (BlockTable)trans.GetObject(doc.Database.BlockTableId, OpenMode.ForRead);
var btr = (BlockTableRecord)trans.GetObject(bt[BlockTableRecord.ModelSpace], OpenMode.ForWrite);
btr.AppendEntity(poly2);
trans.AddNewlyCreatedDBObject(poly2, true);
trans.Commit();
}
}
/// Calculates a new point, using the specified angle and distance. Angle should be specified
/// counter-clockwise from the X-axis.
/// </summary>
public Point2d GetPolarPoint(Point2d ptBase, double angle, double distance)
{
return new Point2d
(ptBase
.X + (distance
* Math
.Cos(angle
)), ptBase
.Y + (distance
* Math
.Sin(angle
))); }