Code Red > .NET
Sorting Civil 3D CogoPoints
(1/1)
sdunn:
I am trying to select points from a drawing, sort them by northing and then by easting so that I can renumber them from north to south and then by west to east. I want to do this as efficiently as possible and I think linq would be the best way assuming I can work with a List<CogoPoint> in this manner.
This doesn't work yet. Is there a better way to do this or a different path I should take?
--- Code - C#: --- using (Transaction tr = db.TransactionManager.StartTransaction()) { // ' If the prompt status is OK, objects were selected if (acSSPrompt.Status == PromptStatus.OK) { ObjectIdCollection idcoll = new ObjectIdCollection(acSSPrompt.Value.GetObjectIds()); foreach (ObjectId OID in idcoll) { CogoPoint p = (OID.GetObject(OpenMode.ForRead) as CogoPoint); SelectedPoints.Append<CogoPoint>(p); } var sortresult = SelectedPoints.OrderByDescending(p.Northing).ThenByDescending(p.Easting); //Renumber the points here tr.Commit(); } else { } }//end using
Thank you,
Stacy
MickD:
Have you tried
--- Code - C#: ---var sortresult = SelectedPoints.OrderByDescending(p => p.Northing).ThenByDescending(p => p.Easting);
You usually need a Lambda expression with Linq that takes the object then gets the object property eg. object => object.Property
You might also want to tack on 'ToList()' to get back an ordered 'List' rather than an IOrderedEnumerable.
hth
sdunn:
Yes, that is what I was missing. Thank you!
MickD:
no problemo :)
Navigation
[0] Message Index
Go to full version