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'.
Solved! Go to Solution.
Solved by _gile. Go to Solution.
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(); }
Can't find what you're looking for? Ask the community or share your knowledge.