| Author |
Message |
zzhang2002
Guest
|
Posted:
Thu Jan 06, 2005 12:06 am Post subject:
How to iterate through Dictionaries collection? |
|
|
Hi! I am trying to create a VBA program to iterate through dictionaries collection and print out all dictionary names. However, the return value of Dictionaries.Item is not AcadDictionary. Rather it returns IAcadObject. But IAcadObject doesn't have a way to cast its object to AcadDictionary object. So the following code doesn' work.
Dim dictCol As AcadDictionaries
Dim iAcadObj As IAcadObject
Dim dict As AcadDictionary
Dim i As Integer
Set dictCol = ThisDrawing.Dictionaries
For i = 0 To dictCol.Count - 1
Set iAcadObj = dictCol(i)
Debug.Print vbTab & iAcadObj.ObjectName
If iAcadObj.ObjectName = "AcDbDictionary" Then
Set dict = iAcadObj
End If
Next i
How can I fix it?
David
|
|
| Back to top |
|
 |
Jeff Mishler
Guest
|
Posted:
Thu Jan 06, 2005 12:21 am Post subject:
Re: How to iterate through Dictionaries collection? |
|
|
Here's a response I made to a similar question over at the AUGI forums:
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
--
Jeff
check out www.cadvault.com
"zzhang2002" <nospam@address.withheld> wrote in message
news:7418809.1104952005184.JavaMail.jive@jiveforum2.autodesk.com...
| Quote: | Hi! I am trying to create a VBA program to iterate through dictionaries
collection and print out all dictionary names. However, the return value
of Dictionaries.Item is not AcadDictionary. Rather it returns IAcadObject.
But IAcadObject doesn't have a way to cast its object to AcadDictionary
object. So the following code doesn' work.
Dim dictCol As AcadDictionaries
Dim iAcadObj As IAcadObject
Dim dict As AcadDictionary
Dim i As Integer
Set dictCol = ThisDrawing.Dictionaries
For i = 0 To dictCol.Count - 1
Set iAcadObj = dictCol(i)
Debug.Print vbTab & iAcadObj.ObjectName
If iAcadObj.ObjectName = "AcDbDictionary" Then
Set dict = iAcadObj
End If
Next i
How can I fix it?
David |
|
|
| Back to top |
|
 |
fantum
Guest
|
Posted:
Thu Jan 06, 2005 12:32 am Post subject:
Re: How to iterate through Dictionaries collection? |
|
|
Dim dictCol As AcadDictionaries
Dim iAcadObj As IAcadObject
Dim dict As AcadDictionary
Dim i As Integer
Set dictCol = ThisDrawing.Dictionaries
For i = 0 To dictCol.Count - 1
Set iAcadObj = dictCol(i)
Debug.Print vbTab & iAcadObj.ObjectName
'If iAcadObj.ObjectName = "AcDbDictionary" Then
If TypeOf iAcadObj Is AcadDictionary Then
Set dict = iAcadObj
End If
Next i
|
|
| Back to top |
|
 |
zzhang2002
Guest
|
Posted:
Thu Jan 06, 2005 7:39 pm Post subject:
Re: How to iterate through Dictionaries collection? |
|
|
Thanks, Jeff.
It looks like some items in AcadDictionaries collection is not a AcadDictionary object.
David |
|
| Back to top |
|
 |
zzhang2002
Guest
|
Posted:
Thu Jan 06, 2005 7:43 pm Post subject:
Re: How to iterate through Dictionaries collection? |
|
|
After the mirable TypeOf operator, I can set an IAcadObj to AcadDictionary. This is cool. Thanks.
So not all AcDbDictionary is AcadDictionary.
David |
|
| Back to top |
|
 |
|
|
|
|