how to create polyline using getPoint() method

how to create polyline using getPoint() method

Anonymous
Not applicable
967 Views
1 Reply
Message 1 of 2

how to create polyline using getPoint() method

Anonymous
Not applicable

i have code for crearting line using getPoint() method but i dont know how do i create polyline like a line. any suggestions?

this is code for creating line:

  Public Shared Sub PlotLine()
            Dim ed As Editor = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument.Editor
            Dim StartPoint As Point3d
            Dim EndPoint As Point3d
            Dim getStartPointOptions As PromptPointOptions = New PromptPointOptions("Pick start point of a new line: ")
            Dim getStartPointResult As PromptPointResult = ed.GetPoint(getStartPointOptions)

            If (getStartPointResult.Status = PromptStatus.OK) Then
                Dim getEndPointOptions As PromptPointOptions = New PromptPointOptions("Pick end point of a new line: ")
                getEndPointOptions.UseBasePoint = false
                getEndPointOptions.BasePoint = getStartPointResult.Value
                Dim getEndPointResult As PromptPointResult = ed.GetPoint(getEndPointOptions)
                If (getEndPointResult.Status = PromptStatus.OK) Then
                    StartPoint = New Point3d(getStartPointResult.Value.X, getStartPointResult.Value.Y, getStartPointResult.Value.Z)
                    EndPoint = New Point3d(getEndPointResult.Value.X, getEndPointResult.Value.Y, getEndPointResult.Value.Z)
                    Dim LineEnt As New Line (StartPoint,EndPoint)
0 Likes
Accepted solutions (1)
968 Views
1 Reply
Reply (1)
Message 2 of 2

_gile
Consultant
Consultant
Accepted solution

Hi,

 

Here's a simple example, another way should be using a Jig.

 

        [CommandMethod("TEST")]
        public void Test()
        {
            var doc = Application.DocumentManager.MdiActiveDocument;
            var db = doc.Database;
            var ed = doc.Editor;

            var ppo = new PromptPointOptions("\nSpecify start point: ");
            var ppr = ed.GetPoint(ppo);
            if (ppr.Status != PromptStatus.OK)
                return;
            var pt0 = ppr.Value;

            ppo.Message = "\nSpecify next point: ";
            ppo.UseBasePoint = true;
            ppo.BasePoint = pt0;
            ppr = ed.GetPoint(ppo);
            if (ppr.Status != PromptStatus.OK)
                return;
            var pt1 = ppr.Value;

            var ucs = ed.CurrentUserCoordinateSystem;
            var normal = ucs.CoordinateSystem3d.Zaxis;
            var plane = new Plane(Point3d.Origin, normal);

            using (var tr = db.TransactionManager.StartTransaction())
            {
                var curSpace = (BlockTableRecord)tr.GetObject(db.CurrentSpaceId, OpenMode.ForWrite);
                var pline = new Polyline();
                pline.Normal = normal;
                pline.Elevation = Point3d.Origin.TransformBy(ucs).Z;
                pline.AddVertexAt(0, pt0.TransformBy(ucs).Convert2d(plane), 0.0, 0.0, 0.0);
                pline.AddVertexAt(1, pt1.TransformBy(ucs).Convert2d(plane), 0.0, 0.0, 0.0);
                curSpace.AppendEntity(pline);
                tr.AddNewlyCreatedDBObject(pline, true);
                db.TransactionManager.QueueForGraphicsFlush();

                int i = 2;
                ppo.AllowNone = true;
                while (true)
                {
                    pt0 = pt1;
                    ppo.BasePoint = pt0;
                    ppr = ed.GetPoint(ppo);
                    if (ppr.Status != PromptStatus.OK)
                        break;
                    pt1 = ppr.Value;
                    pline.AddVertexAt(i, pt1.TransformBy(ucs).Convert2d(plane), 0.0, 0.0, 0.0);
                    db.TransactionManager.QueueForGraphicsFlush();
                    i++;
                }
                tr.Commit();
            }
        }


Gilles Chanteau
Programmation AutoCAD LISP/.NET
GileCAD
GitHub