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

renumber points related to polyline

2 REPLIES 2
SOLVED
Reply
Message 1 of 3
Ahmmed-saber
180 Views, 2 Replies

renumber points related to polyline

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

Ahmmedsaber_1-1720411828988.png

need this numbering

Ahmmedsaber_0-1720411813305.png

 

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();
}
}
2 REPLIES 2
Message 2 of 3
_gile
in reply to: Ahmmed-saber

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.



Gilles Chanteau
Programmation AutoCAD LISP/.NET
GileCAD
GitHub

Message 3 of 3
Ahmmed-saber
in reply to: _gile

thanks for your help

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

Post to forums  

Forma Design Contest


AutoCAD Beta