Community
Civil 3D Customization
Welcome to Autodesk’s AutoCAD Civil 3D Forums. Share your knowledge, ask questions, and explore popular AutoCAD Civil 3D Customization topics.
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

sorting alignment collection by alignment name

4 REPLIES 4
Reply
Message 1 of 5
Anonymous
342 Views, 4 Replies

sorting alignment collection by alignment name

Good aftenoon, I have a bunch of alignments named based on the station of the mainline alignment they run askew. I'd like to iterate the collection of alignments to create profile views but some ofhte alignments were created out of order (non sequential moving up the main line alignment).

How do I sort the alignments collection of a site in order to get them in increasing order (based on their names). Do I need to create an array of alignments and then process it? If so, can you please provide an example of this?

Thanks,
Josh
4 REPLIES 4
Message 2 of 5
Anonymous
in reply to: Anonymous

Search Google for "VBA BUBBLESORT" is one way utilizing an array. Or, search
the land-desktop.customization group for a VBA macro I wrote for Station &
Offset Labeling. It won't convert exactly, but I do grab all of the LDT
alignments and sort them by name.

"jlund" wrote in message news:5909057@discussion.autodesk.com...
> Good aftenoon, I have a bunch of alignments named based on the station of
> the mainline alignment they run askew. I'd like to iterate the collection
> of alignments to create profile views but some ofhte alignments were
> created out of order (non sequential moving up the main line alignment).
>
> How do I sort the alignments collection of a site in order to get them in
> increasing order (based on their names). Do I need to create an array of
> alignments and then process it? If so, can you please provide an example
> of this?
>
> Thanks,
> Josh
Message 3 of 5
Anonymous
in reply to: Anonymous

Thanks, Jeff. I found a bubble sorting algorithm and adapted it to this.

Josh
Message 4 of 5
Sinc
in reply to: Anonymous

Here's an example of how you could do it in .NET. This sample has no error checking and does not work on Siteless Alignments, but it illustrates the basic procedure.

With this option, there is no need to manually write a sort algorithm - it is included in the List<> class. We merely need to specify what operation to use for comparing two items.

[code]
using System;
using System.Collections.Generic;
using Autodesk.AutoCAD.ApplicationServices;
using Autodesk.AutoCAD.EditorInput;
using Autodesk.AECC.Interop.Land;

namespace Sample
{
public class Sample
{
public List GetAlignmentOrderedList(AeccSite site)
{
Editor ed = Application.DocumentManager.MdiActiveDocument.Editor;
List alignmentList = new List();
foreach (AeccAlignment align in site.Alignments)
alignmentList.Add(align);
alignmentList.Sort(new AlignmentComparer());
return alignmentList;
}

private class AlignmentComparer : IComparer
{
public int Compare(AeccAlignment a1, AeccAlignment a2)
{
return a1.Name.CompareTo(a2.Name);
}
}
}
}
[/code]


-- Sinc
http://ejsurveying.com
http://www.quux.biz (Sincpac-C3D)
Sinc
Message 5 of 5
Sinc
in reply to: Anonymous

Drat! The cheesy forum software mangled that posting.

Everywhere that the word "List" occurs in the code I just posted, it should have said:

List<AeccAlignment>
Sinc

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

Post to forums  

Rail Community


 

Autodesk Design & Make Report