Author Topic: How can I sort the layouts using the "natural sort"?  (Read 1983 times)

0 Members and 1 Guest are viewing this topic.

teslaxx

  • Guest
How can I sort the layouts using the "natural sort"?
« on: November 30, 2010, 03:03:44 AM »
My Situation:
I have 100 layouts in my drawing: Layer1 Layer2 Layer3 Layer4 Layer5.... and I need to insert a number in each one, (see here: http://www.theswamp.org/index.php?topic=35909.0 ... Thanx to Jeff H and T.Willey).
But the way that the layouts are ordered this way:  Layer 1 Layer 10 ... Layer 19 Layer 2 Layer 20, so number 2 appears in Layer 10, 3 appears in Layer 11.

An idea would by to see what are the last 2 characters from the name of the string, but is very common in my situation that one or more layer could be deleted. Ex: Layer 1 Layer 2 Layer 3 Layer 4

Any solutions>?

teslaxx

  • Guest
Re: How can I sort the layouts using the "natural sort"?
« Reply #1 on: November 30, 2010, 06:59:51 AM »
Ok, I resolsed it.

1. Firstly I found a way to natural sort in C# by using the code from here: http://www.interact-sw.co.uk/iangblog/2007/12/13/natural-sorting .
2. I took the names of the layouts and put them in a String array and I used the code from 1 and sort that array.
3. I put all the elements from the string array in a ArrayList.
4. In the loop of DBDictionary, I took the name of the Layout and I called the IndexOf of the ArrayList.

Jeff H

  • Needs a day job
  • Posts: 6144
Re: How can I sort the layouts using the "natural sort"?
« Reply #2 on: November 30, 2010, 07:51:41 AM »
Here is another way if you want the order of layout tabs are

Code: [Select]
<CommandMethod("LayoutTabList")> _
    Public Sub LayoutTabList()

        Dim doc As Document = Application.DocumentManager.MdiActiveDocument
        Dim db As Database = doc.Database
        Dim ed As Editor = doc.Editor

        Dim layAndTab As SortedDictionary(Of Integer, String) = New SortedDictionary(Of Integer, String)

        Using trx As Transaction = db.TransactionManager.StartTransaction()

            Dim layDict As DBDictionary = db.LayoutDictionaryId.GetObject(OpenMode.ForRead)
            For Each entry As DBDictionaryEntry In layDict
                Dim lay As Layout = CType(entry.Value.GetObject(OpenMode.ForRead), Layout)
                layAndTab.Add(lay.TabOrder, lay.LayoutName)
            Next

            trx.Commit()
        End Using

        For Each v In layAndTab.Values
            ed.WriteMessage(v & vbCrLf)
        Next

    End Sub