PDA

View Full Version : Dictionaries exist?



solarcad
2004-12-09, 07:00 PM
How can you check if a dictionary exists? Know you can check for an object in a dictionary but want to error check if it exists before creating it.

Related - how can you list the names of existing dictionaries that may have been created in the drawing?

Jeff_M
2004-12-09, 10:35 PM
How can you check if a dictionary exists? Know you can check for an object in a dictionary but want to error check if it exists before creating it.

Related - how can you list the names of existing dictionaries that may have been created in the drawing?
Here's a sample Sub that lists all defined dictionaries and a function that will return true/false for the existence og a Dictionary


Sub getDicts()
Dim oDicts As AcadDictionaries
Dim odict As AcadObject

Set oDicts = ThisDrawing.Dictionaries
For Each odict In oDicts
On Error Resume Next
Debug.Print odict.Name
If Err.Number <> 0 Then
Err.Clear
Debug.Print "No name for this object: " & odict.ObjectName & " - ID: " & odict.ObjectID
'must do this since Groups, and other, are part of the Dictionaries Collection but have no Name property
End If
Next
End Sub

Function DictExists(strName As String) As Boolean
Dim odict As AcadObject
On Error Resume Next
Set odict = ThisDrawing.Dictionaries.Item(strName)
If Err.Number <> 0 Then
DictExists = False
Else
DictExists = True
End If
Err.Clear
On Error GoTo 0

End Function

solarcad
2004-12-13, 10:01 PM
Thanks, had problem getting the error checking to work right.