Message 1 of 2
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
While we normally use 'PL' command for polyline we are able to see the line as we select the points. but when I programmatically try this it shows me the message to select the ployline points but it does not show the line. so its difficult to find the start point to close it. is there any way to do this
Document doc = Application.DocumentManager.MdiActiveDocument;
Database db = doc.Database;
Editor ed = doc.Editor;
// Prompt for the polyline points
PromptPointOptions ppo = new PromptPointOptions("\nEnter the first point of the polyline: ");
PromptPointResult ppr = ed.GetPoint(ppo);
if (ppr.Status != PromptStatus.OK) return;
Point3d startPoint = ppr.Value;
Polyline poly = new Polyline();
poly.AddVertexAt(0, new Point2d(startPoint.X, startPoint.Y), 0, 0, 0);
while (true)
{
ppo.Message = "\nEnter the next point of the polyline (or press Enter to finish): ";
ppr = ed.GetPoint(ppo);
if (ppr.Status != PromptStatus.OK) break;
Point3d nextPoint = ppr.Value;
poly.AddVertexAt(poly.NumberOfVertices, new Point2d(nextPoint.X, nextPoint.Y), 0, 0, 0);
}
if (poly.NumberOfVertices < 2)
{
ed.WriteMessage("\nA polyline needs at least two points.");
return;
}
// Create the polyline
using (Transaction tr = db.TransactionManager.StartTransaction())
{
doc.LockDocument();
BlockTable bt = (BlockTable)tr.GetObject(db.BlockTableId, OpenMode.ForRead);
BlockTableRecord btr = (BlockTableRecord)tr.GetObject(bt[BlockTableRecord.ModelSpace], OpenMode.ForWrite);
btr.AppendEntity(poly);
tr.AddNewlyCreatedDBObject(poly, true);
tr.Commit();
}
Solved! Go to Solution.