Hi,
please give this a try:
Parameter:
PointCollection is a Collection of 2D Points
Layer is the layer where the object draws
And don't Forget the usings:
using Autodesk.AutoCAD.DatabaseServices;
using Autodesk.AutoCAD.Geometry;
public static class ACADPolyLine
{
public static void CreatePolyline(Point2dCollection PointCollection, string Layer)
{
Autodesk.AutoCAD.ApplicationServices.Document m_Document =
Autodesk.AutoCAD.ApplicationServices.Core.Application.DocumentManager.MdiActiveDocument;
using (Transaction m_Transaction = m_Document.Database.TransactionManager.StartTransaction())
{
if (PointCollection != null)
{
BlockTable m_BlockTable = (BlockTable)m_Transaction.GetObject(m_Document.Database.BlockTableId, OpenMode.ForRead);
BlockTableRecord m_BlockTableRecord =
(BlockTableRecord)m_Transaction.GetObject(m_BlockTable[BlockTableRecord.ModelSpace], OpenMode.ForWrite);
Autodesk.AutoCAD.DatabaseServices.Polyline m_Polyline = new Polyline()
{
Layer = Layer
};
int i = 0;
foreach (Autodesk.AutoCAD.Geometry.Point2d m_Point in PointCollection)
{
m_Polyline.AddVertexAt(i, m_Point, 0, 0, 0);
i++;
Autodesk.AutoCAD.DatabaseServices.Circle m_Circle = new Circle()
{
Center = new Autodesk.AutoCAD.Geometry.Point3d(m_Point.X, m_Point.Y, 0),
Radius = 10,
Layer = Layer
};
m_BlockTableRecord.AppendEntity(m_Circle);
m_Transaction.AddNewlyCreatedDBObject(m_Circle, true);
}
m_BlockTableRecord.AppendEntity(m_Polyline);
m_Transaction.AddNewlyCreatedDBObject(m_Polyline, true);
}
m_Transaction.Commit();
}
}
}
I hope thats helps.
Regards Jürgen
I hope my tip helps. If so then give me kudos and mark the tip as a solution.
Thanks.
Jürgen A. Becker
Building Services
Development and Support
Autodesk Forge Spezialist
https://www.CAD-Becker.de