Author Topic: Sorting Civil 3D CogoPoints  (Read 1530 times)

0 Members and 1 Guest are viewing this topic.

sdunn

  • Newt
  • Posts: 90
Sorting Civil 3D CogoPoints
« on: July 14, 2020, 10:16:43 PM »
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#: [Select]
  1.             using (Transaction tr = db.TransactionManager.StartTransaction())
  2.             {
  3.                 // ' If the prompt status is OK, objects were selected
  4.                 if (acSSPrompt.Status == PromptStatus.OK)
  5.                 {
  6.                     ObjectIdCollection idcoll = new ObjectIdCollection(acSSPrompt.Value.GetObjectIds());
  7.                    
  8.                     foreach (ObjectId OID in idcoll)
  9.                     {
  10.                         CogoPoint p = (OID.GetObject(OpenMode.ForRead) as CogoPoint);
  11.                         SelectedPoints.Append<CogoPoint>(p);
  12.                     }
  13.                    var sortresult = SelectedPoints.OrderByDescending(p.Northing).ThenByDescending(p.Easting);
  14.  
  15.                     //Renumber the points here
  16.  
  17.                    tr.Commit();
  18.                 }
  19.                 else
  20.                 {
  21.                 }
  22.             }//end using
  23.  

Thank you,
Stacy

MickD

  • King Gator
  • Posts: 3619
  • (x-in)->[process]->(y-out) ... simples!
Re: Sorting Civil 3D CogoPoints
« Reply #1 on: July 15, 2020, 02:45:58 AM »
Have you tried

Code - C#: [Select]
  1. 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

« Last Edit: July 15, 2020, 02:50:08 AM by MickD »
"Short cuts make long delays,' argued Pippin.”
J.R.R. Tolkien

sdunn

  • Newt
  • Posts: 90
Re: Sorting Civil 3D CogoPoints
« Reply #2 on: July 15, 2020, 02:09:06 PM »
Yes, that is what I was missing.  Thank you!

MickD

  • King Gator
  • Posts: 3619
  • (x-in)->[process]->(y-out) ... simples!
Re: Sorting Civil 3D CogoPoints
« Reply #3 on: July 15, 2020, 05:03:14 PM »
no problemo :)
"Short cuts make long delays,' argued Pippin.”
J.R.R. Tolkien