in the following code after selecting points sort them according to the position after that create a text number for them
but I want to number them according to polyline start form polyline start point and round with polyline
need this numbering
public static void PointNumber()
{
Document doc = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument;
Database db = doc.Database;
Editor ed = doc.Editor;
using (Transaction trans = db.TransactionManager.StartTransaction())
{
List<DBPoint> allPoints = new List<DBPoint>();
var count = 1;
BlockTable bt = trans.GetObject(db.BlockTableId, OpenMode.ForRead) as BlockTable;
BlockTableRecord btr = trans.GetObject(bt[BlockTableRecord.ModelSpace], OpenMode.ForWrite) as BlockTableRecord;
TypedValue[] tv = new TypedValue[1];
tv.SetValue(new TypedValue((int)DxfCode.Start, "point"), 0);
SelectionFilter filter = new SelectionFilter(tv);
PromptSelectionResult ssPrompt;
ssPrompt = ed.GetSelection(filter);
if (ssPrompt.Status == PromptStatus.OK)
{
SelectionSet ss = ssPrompt.Value;
foreach (SelectedObject sObj in ss)
{
DBPoint point = trans.GetObject(sObj.ObjectId, OpenMode.ForRead) as DBPoint;
allPoints.Add(point);
var text = new DBText();
}
}
foreach (DBPoint point in allPoints.OrderBy(p => p.Position.X).ThenBy(p => p.Position. Y).ToList())
{
var text = new DBText();
text.Position = point.Position;
text.Height = 1.5;
text.TextString = $"{(count)}";
text.ColorIndex = 5;
btr.AppendEntity(text);
trans.AddNewlyCreatedDBObject(text, true);
count++;
}
trans.Commit();
}
}
Solved! Go to Solution.
Solved by _gile. Go to Solution.
Hi,
You have to open the polyline for read and order the points by the polyline parameter at point.
Replace:
allPoints.OrderBy(p => p.Position.X).ThenBy(p => p.Position. Y).ToList()
with:
allPoints.OrderBy(p => polyline.GetParameterAtPoint(p))
Please, use the 'Insert/Edit code sample' button [</>] when you paste code.
Can't find what you're looking for? Ask the community or share your knowledge.