Sorting a dictionary of Layers

Discussion in 'AutoCAD' started by Dave F., Aug 16, 2004.

  1. Dave F.

    Dave F. Guest

    Hi
    A2002

    I'm trying to sort a Script Dictionary. It has the layer name in the keys &
    the layer Object in the items.

    1. I can swap the keys (string) values as shown below, but the Items
    (object) won't budge
    Where an I going wrong?.

    2. is there a way to swap both Keys/Items in one go ie Dict(0)=Dict(5)
    instead of doing them separately?

    3. I've seen a routine on MSN for sorting a dictionary
    http://support.microsoft.com/default.aspx?scid=kb;en-us;246067
    That sorts a string based dict, but a) I don't know how to change it so it
    can accept objects & b) it creates arrays to do the sorting which confuses
    me because I thought = Dict.Keys returns an array anyway.



    Sub test()
    Dim LayObj As AcadLayer
    Dim DictSort As Variant
    Dim Dict As New Dictionary ' script dictionary (scripting runtime ref)
    Dim KK As Variant, It As Variant

    With ThisDrawing
    For Each LayObj In .Layers
    Dict.Add LayObj.Name, LayObj ' store it - Key:Layer Name, Item:
    Layer Object
    Next ' Lay
    End With ' thisdrawing
    KK = Dict.Keys
    It = Dict.Items ' these are OBJECTS not strings

    KK(0) = KK(5) 'swaps the keys
    It(0) = It(5)
    End Sub
     
    Dave F., Aug 16, 2004
    #1
Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments (here). After that, you can post your question and our members will help you out.