Message 1 of 6
More Dictionary questions

Not applicable
12-26-2001
08:39 AM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
Hi all you dictionary fans out there.
I'm think I want to use dictionaries for data storage for a routine I'm
working on and have been reading and re-reading every post in the archive
and every helpfile on dictionaries etc but i'm still fuzzy on all this.
are dictionaries and extension dictionaries the same thing or two different
things?
Is an extension dictionary attatched to an entity like xdata? is it the same
as xdata?
Does xdata only hold one key and one value?
If I make dictionaries under the Dictionaries collection and it has a 'name'
how do i get at that name? .objectName only returns AcDbDictionary or
something like that.
Sub readDicts()
Set colDicts = ThisDrawing.Dictionaries
Dim howMany As Integer, i As Integer
howMany = colDicts.count
Debug.Print "There are " & howMany & " dictionaries"
For i = 0 To colDicts.count - 1
MsgBox colDicts.Item(i).ObjectName
Next
End Sub
Coming from lisp I expect to have to check for the existence before adding
to it like
(if dictx
;exists
blah
; else
blah blah
);end if
but it seems like in vb what I'm seeing is
on error resume next or go to or?
try to do something with dictx
- then if dictx didn't exist the error handler takes care of it.
That just seems so wrong after having to prevent all errors with lisp
previously
but I guess i'll just have to get used to it.
So maybe I don't have to be able to get at my dictionary name to see if it's
there?
so what I'm trying is this:
Sub PutInDictionary(obj As AcadObject) As AcadDictionary
dictName = "whatever"
Set colDicts = ThisDrawing.Dictionaries
On Error Resume Next
Set newDict = ThisDrawing.Dictionaries(dictName)
If Err Then
err.clear???
'
'so create it
Set newDict = colDicts.Add(dictName)
'example of info I want to store
newDictEntry = newDict.AddXRecord("PtList", obj.Coordinates)
newDictEntry = newDict.AddXRecord("hndl", obj.Handle)
newDictEntry = newDict.AddXRecord("layr", obj.Layer)
Else
'
newDictEntry = newDict.AddXRecord("PtList", obj.Coordinates)
newDictEntry = newDict.AddXRecord("hndl", obj.Handle)
newDictEntry = newDict.AddXRecord("layr", obj.Layer)
End If
For i = 0 To newDict.count - 1
MsgBox newDict.Item(i).GetName
Debug.Print newDict.Item(i).GetName
Next i
End Sub
obviously I'm flailing about here, the example AddXrecord just adds one item
so I'm confused as to how to do the above.
Any guidance mucho appreciated.
What I want to end up with is a dictionary with a record for each of x
number of layers.
Each record will have a list of each item on that layer (polylines)
Each list will have various items of info like point list, size, etc.
I don't know if I need a different dictionary for each layer and then a
dictionary containing all those dictionaries?
And would the information lists for each pline be separate dictionaries or
separate xrecords within a dictionary?
Or can it all be one big dictionary with just xrecords to store the lists?
Is the xrecord itself an array of two arrays: a key array and a value array?
I am so confused! ?:<
Mark
I'm think I want to use dictionaries for data storage for a routine I'm
working on and have been reading and re-reading every post in the archive
and every helpfile on dictionaries etc but i'm still fuzzy on all this.
are dictionaries and extension dictionaries the same thing or two different
things?
Is an extension dictionary attatched to an entity like xdata? is it the same
as xdata?
Does xdata only hold one key and one value?
If I make dictionaries under the Dictionaries collection and it has a 'name'
how do i get at that name? .objectName only returns AcDbDictionary or
something like that.
Sub readDicts()
Set colDicts = ThisDrawing.Dictionaries
Dim howMany As Integer, i As Integer
howMany = colDicts.count
Debug.Print "There are " & howMany & " dictionaries"
For i = 0 To colDicts.count - 1
MsgBox colDicts.Item(i).ObjectName
Next
End Sub
Coming from lisp I expect to have to check for the existence before adding
to it like
(if dictx
;exists
blah
; else
blah blah
);end if
but it seems like in vb what I'm seeing is
on error resume next or go to or?
try to do something with dictx
- then if dictx didn't exist the error handler takes care of it.
That just seems so wrong after having to prevent all errors with lisp
previously
but I guess i'll just have to get used to it.
So maybe I don't have to be able to get at my dictionary name to see if it's
there?
so what I'm trying is this:
Sub PutInDictionary(obj As AcadObject) As AcadDictionary
dictName = "whatever"
Set colDicts = ThisDrawing.Dictionaries
On Error Resume Next
Set newDict = ThisDrawing.Dictionaries(dictName)
If Err Then
err.clear???
'
'so create it
Set newDict = colDicts.Add(dictName)
'example of info I want to store
newDictEntry = newDict.AddXRecord("PtList", obj.Coordinates)
newDictEntry = newDict.AddXRecord("hndl", obj.Handle)
newDictEntry = newDict.AddXRecord("layr", obj.Layer)
Else
'
newDictEntry = newDict.AddXRecord("PtList", obj.Coordinates)
newDictEntry = newDict.AddXRecord("hndl", obj.Handle)
newDictEntry = newDict.AddXRecord("layr", obj.Layer)
End If
For i = 0 To newDict.count - 1
MsgBox newDict.Item(i).GetName
Debug.Print newDict.Item(i).GetName
Next i
End Sub
obviously I'm flailing about here, the example AddXrecord just adds one item
so I'm confused as to how to do the above.
Any guidance mucho appreciated.
What I want to end up with is a dictionary with a record for each of x
number of layers.
Each record will have a list of each item on that layer (polylines)
Each list will have various items of info like point list, size, etc.
I don't know if I need a different dictionary for each layer and then a
dictionary containing all those dictionaries?
And would the information lists for each pline be separate dictionaries or
separate xrecords within a dictionary?
Or can it all be one big dictionary with just xrecords to store the lists?
Is the xrecord itself an array of two arrays: a key array and a value array?
I am so confused! ?:<
Mark