Draw Polyline and place circular block on all the vertex of Polyline

Draw Polyline and place circular block on all the vertex of Polyline

Anonymous
Not applicable
850 Views
2 Replies
Message 1 of 3

Draw Polyline and place circular block on all the vertex of Polyline

Anonymous
Not applicable

Sample.PNG

 

Hi Gilles,

 

I have a requirement as when the user click on autocad it has to draw polyline and each click on vertexes it should place a uniform size circle blocks.

 

The screen shot which I have provided below.

 

 

Regards

 

Alex Andrews.

0 Likes
851 Views
2 Replies
Replies (2)
Message 2 of 3

Juergen_Becker
Advocate
Advocate

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


CAD-Becker.de
https://www.CAD-Becker.de

Message 3 of 3

Anonymous
Not applicable

Thanks Juergen

0 Likes