Iterating Dictionaries Collection

Discussion in 'AutoCAD' started by Ben Rand, Jun 1, 2004.

  1. Ben Rand

    Ben Rand Guest

    I'm stumped. I'm trying to return a collection of the dictionary names in a drawing with the following code:

    Public Function ListDictionaries() As Collection
    Dim oDict As AcadDictionary
    Dim col As New Collection

    Debug.Print "Found " & ThisDrawing.Dictionaries.Count & " dictionaries."
    For Each oDict In ThisDrawing.Dictionaries
    col.Add oDict.Name
    Next oDict 'Run-time error 13: type mismatch occurs here

    Set ListDictionaries = col
    Set oDict = Nothing
    Set col = Nothing
    End Function

    But I get a run-time error 13: type mismatch when it hits the Next statement. Is there some secret way to iterate dictionaries that I don't know about?

    Thanks,

    Ben Rand
    CAD Manager
    CEntry Constructors & Engineers
     
    Ben Rand, Jun 1, 2004
    #1
  2. Ben,

    Not all objects in that collection are dictionaries.

    Public Function ListDictionaries() As Collection
    Dim oDict As AcadObject '<-change
    Dim col As New Collection

    Debug.Print "Found " & ThisDrawing.Dictionaries.Count & " dictionaries."
    '<-bogus
    For Each oDict In ThisDrawing.Dictionaries
    If TypeOf oDict Is AcadDictionary Then '<-added
    col.Add oDict.Name
    End If '<-added
    Next oDict

    Set ListDictionaries = col
    Set oDict = Nothing
    Set col = Nothing
    End Function


    --
    R. Robert Bell


    I'm stumped. I'm trying to return a collection of the dictionary names in a
    drawing with the following code:

    Public Function ListDictionaries() As Collection
    Dim oDict As AcadDictionary
    Dim col As New Collection

    Debug.Print "Found " & ThisDrawing.Dictionaries.Count & " dictionaries."
    For Each oDict In ThisDrawing.Dictionaries
    col.Add oDict.Name
    Next oDict 'Run-time error 13: type mismatch occurs here

    Set ListDictionaries = col
    Set oDict = Nothing
    Set col = Nothing
    End Function

    But I get a run-time error 13: type mismatch when it hits the Next
    statement. Is there some secret way to iterate dictionaries that I don't
    know about?

    Thanks,

    Ben Rand
    CAD Manager
    CEntry Constructors & Engineers
     
    R. Robert Bell, Jun 1, 2004
    #2
  3. Ben Rand

    Ben Rand Guest

    Robert,

    Thanks for the quick response (as usual). Is it just me, or is it strange
    that items other than dictionaries would be stored in the dictionaries
    collection?

    I modified the routine to output the objectnames of objects that were not
    AcadDictionary objects, and got back a list of 3 AcDbDictionary objects
    (umm...?), an AcDbWipeoutVariables object, and an AcDbXrecord object.

    Anyway, despite some lingering confusion over those results, your help gets
    me back on my way. Thanks!

    Ben
     
    Ben Rand, Jun 1, 2004
    #3
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.