.NET
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

How to draw polyline from collection of 3d points?

2 REPLIES 2
SOLVED
Reply
Message 1 of 3
Anonymous
1858 Views, 2 Replies

How to draw polyline from collection of 3d points?

Hi. How can I draw a polyline from a previously defined collection of 3d points?

I create a collection by:

Dim Linia = New Point3dCollection

Then I add points to this collection through:

Linia.Add(New Point3d((Val(Py)), (Val(Px)), 0))

And I want to draw Polyline from this collection. I use this code:

            Using acLckDoc As DocumentLock = acDoc.LockDocument
                Using acTrans As Transaction = acCurDb.TransactionManager.StartTransaction()
                    acBlkTbl = acTrans.GetObject(acCurDb.BlockTableId, OpenMode.ForRead)
                    acBlkTblRec = acTrans.GetObject(acBlkTbl(BlockTableRecord.ModelSpace),
                OpenMode.ForWrite)
                    Using acPLine As Polyline = New Polyline()
                        acPLine.AddVertexAt(0, Linia, 0, 0, 0)
                        acBlkTblRec.AppendEntity(acPLine)
                        acTrans.AddNewlyCreatedDBObject(acPLine, True)
                        acPLine.ColorIndex = 1
                    End Using
                    acTrans.Commit()
                End Using
            End Using

But this code causes the following error:

Error BC30311 Value of type 'Point3dCollection' cannot be converted to 'Point2d'.

Tags (1)
2 REPLIES 2
Message 2 of 3
_gile
in reply to: Anonymous

Hi,

 

Polyline.AddVertexAt() method requires Point2d as argument, so you have to iterate through the Point3dCollection and convert each Point3d to a Point2d, this can be done using the Point3d.Convert2d() method passing it the plane you want to draw the polyline on.

 

Here's a little example to draw the polyline on the XY plane.

 

            using (doc.LockDocument())
            using (var tr = doc.TransactionManager.StartTransaction())
            using (var pline = new Polyline())
            {
                var plane = new Plane(Point3d.Origin, Vector3d.ZAxis);
                for (int i = 0; i < points.Count; i++)
                {
                    pline.AddVertexAt(i, points[i].Convert2d(plane), 0.0, 0.0, 0.0);
                }
                var ms = (BlockTableRecord)tr.GetObject(SymbolUtilityServices.GetBlockModelSpaceId(db), OpenMode.ForWrite);
                ms.AppendEntity(pline);
                tr.AddNewlyCreatedDBObject(pline, true);
                tr.Commit();
            }


Gilles Chanteau
Programmation AutoCAD LISP/.NET
GileCAD
GitHub

Message 3 of 3
Anonymous
in reply to: _gile

Thank you very much.

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Forma Design Contest


AutoCAD Beta