Dictionaries collection
CADForums.net Forum Index CADForums.net
Discussion of AutoCAD and other CAD software.
 
 FAQFAQ   MemberlistMemberlist     RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 
 
Google
 
Web cadforums.net
Dictionaries collection

 
Post new topic   Reply to topic    CADForums.net Forum Index -> VBA
Author Message
Laurie Comerford
Guest





Posted: Sat Apr 02, 2005 10:03 am    Post subject: Dictionaries collection Reply with quote

Hi,

I have been experimenting with using the dictionaries collection as a means
of storing data in a drawing.

The following code is creating an error.

Dim oDict As AcadDictionary

For Each oDict in ThisDrawing.Dictionaries
If oDict.Name = "MyDictionary" Then
DoSomething
End If
Next

It seems that the Dictionaries collection contains a couple of Items which
don't have a name.or even show up as dictionaries.

The code below runs without error.

For i = 5 to ThisDrawing.Dictionaries.Count
If ThisDrawing.Dictionaries.Item(i).Name = "MyDictionary" Then
Do Something
End If
Next

At the moment I'm working in Land Desktop R3 and my drawing has 26
dictionaries. Is this normal? Roughly how many default dictionaries do you
find in a standard AutoCAD drawing.

The following code works in respect of finding my dictionary:

On Error Resume Next
Set oDict = ThisDrawing.Dictionaries.Item("MyDictionary")
If Err <> 0 Then
MsgBox "You haven't created this dictionary yet"
End If

I found this in the help file:
"Dictionaries: The return value type for this method is IAcadObject. This
allows you to retrieve named objects from the dictionaries collection that
are not of the type AcadDictionary. "

Does this mean that the first code segment could be made to work by using a
TypeOf test along the lines below:

Dim oDict As Object
For Each oDict in ThisDrawing.Dictionaries
If TypeOf oDict Is AcadDictionary Then
If oDict.Name = "MyDictionary" Then
DoSomething
End If
End If
Next
--


Laurie Comerford
CADApps
www.cadapps.com.au

Back to top
Jeff Mishler
Guest





Posted: Sat Apr 02, 2005 10:03 am    Post subject: Re: Dictionaries collection Reply with quote

Hi Laurie, See my comments in-line

"Laurie Comerford" <laurie@DeleteThiscadapps.com.au> wrote in message
news:424e42c6_1@newsprd01...
Quote:
Hi,

I have been experimenting with using the dictionaries collection as a
means
of storing data in a drawing.

The following code is creating an error.

snip


Quote:
It seems that the Dictionaries collection contains a couple of Items which
don't have a name.or even show up as dictionaries.

[JM]Yep, things like Groups, raster_variables, layouts, and other obvious
things.
Quote:

The code below runs without error.

[JM] Yuck....
Quote:


At the moment I'm working in Land Desktop R3 and my drawing has 26
dictionaries. Is this normal? Roughly how many default dictionaries do
you
find in a standard AutoCAD drawing.

[JM] I just checked my current drawing and there are 38 in it, currently
using LDD3 but I think that this drawing was started in S8
Quote:

The following code works in respect of finding my dictionary:

On Error Resume Next
Set oDict = ThisDrawing.Dictionaries.Item("MyDictionary")
If Err <> 0 Then
MsgBox "You haven't created this dictionary yet"
End If

I found this in the help file:
"Dictionaries: The return value type for this method is IAcadObject. This
allows you to retrieve named objects from the dictionaries collection that
are not of the type AcadDictionary. "

Does this mean that the first code segment could be made to work by using
a
TypeOf test along the lines below:

Dim oDict As Object
For Each oDict in ThisDrawing.Dictionaries
If TypeOf oDict Is AcadDictionary Then
If oDict.Name = "MyDictionary" Then
DoSomething
End If
End If
Next
--
[JM] Yes, the above code works quite well. Of course I would modify it

slightly though:
Dim oDictTest As Object
Dim oDict As AcadDictionary

For Each oDictTest In ThisDrawing.Dictionaries
If TypeOf oDictTest Is AcadDictionary Then
If oDictTest.Name = "MyDictionary" Then
Set oDict = oDictTest
'Do stuff with oDict
End If
End If
Next

Jeff
Back to top
Tony Tanzillo
Guest





Posted: Sat Apr 02, 2005 8:43 pm    Post subject: Re: Dictionaries collection Reply with quote

Right. A dictionary (which is what the dictionaries collection
itself is), can contain any object derived from AcadObject, so
you can't assume that everything in the collection is an
AcadDictionary.

You can either use typeof, or just try to assign each item
to a variable dim'd as AcadDictionary, and trap the error
that occurs if its not an AcadDictionary.

--
http://www.caddzone.com

AcadXTabs: MDI Document Tabs for AutoCAD 2004/2005/2006
http://www.acadxtabs.com

"Laurie Comerford" <laurie@DeleteThiscadapps.com.au> wrote in message news:424e42c6_1@newsprd01...
Quote:
Hi,

I have been experimenting with using the dictionaries collection as a means
of storing data in a drawing.

The following code is creating an error.

Dim oDict As AcadDictionary

For Each oDict in ThisDrawing.Dictionaries
If oDict.Name = "MyDictionary" Then
DoSomething
End If
Next

It seems that the Dictionaries collection contains a couple of Items which
don't have a name.or even show up as dictionaries.

The code below runs without error.

For i = 5 to ThisDrawing.Dictionaries.Count
If ThisDrawing.Dictionaries.Item(i).Name = "MyDictionary" Then
Do Something
End If
Next

At the moment I'm working in Land Desktop R3 and my drawing has 26
dictionaries. Is this normal? Roughly how many default dictionaries do you
find in a standard AutoCAD drawing.

The following code works in respect of finding my dictionary:

On Error Resume Next
Set oDict = ThisDrawing.Dictionaries.Item("MyDictionary")
If Err <> 0 Then
MsgBox "You haven't created this dictionary yet"
End If

I found this in the help file:
"Dictionaries: The return value type for this method is IAcadObject. This
allows you to retrieve named objects from the dictionaries collection that
are not of the type AcadDictionary. "

Does this mean that the first code segment could be made to work by using a
TypeOf test along the lines below:

Dim oDict As Object
For Each oDict in ThisDrawing.Dictionaries
If TypeOf oDict Is AcadDictionary Then
If oDict.Name = "MyDictionary" Then
DoSomething
End If
End If
Next
--


Laurie Comerford
CADApps
www.cadapps.com.au



Back to top
Mark Propst
Guest





Posted: Sun Apr 03, 2005 7:44 am    Post subject: Re: Dictionaries collection Reply with quote

Hi Tony,
I'd be interested to know if you have a preference for either of the two
ways which both "work".
From the standpoint of a criteria of professionalism in programming, - or
just doing it the 'right' way -
would there be a reason to prefer one over the other?
1) the error trapping method
or
2) the type-testing method
:-)
Mark

"Tony Tanzillo" <tony.tanzillo@U_KNOW_WHERE.com> wrote in message
news:424ebdcd$1_3@newsprd01...
Quote:
Right. A dictionary (which is what the dictionaries collection
itself is), can contain any object derived from AcadObject, so
you can't assume that everything in the collection is an
AcadDictionary.

You can either use typeof, or just try to assign each item
to a variable dim'd as AcadDictionary, and trap the error
that occurs if its not an AcadDictionary.

--
http://www.caddzone.com

AcadXTabs: MDI Document Tabs for AutoCAD 2004/2005/2006
http://www.acadxtabs.com

"Laurie Comerford" <laurie@DeleteThiscadapps.com.au> wrote in message
news:424e42c6_1@newsprd01...
Hi,

I have been experimenting with using the dictionaries collection as a
means
of storing data in a drawing.

The following code is creating an error.

Dim oDict As AcadDictionary

For Each oDict in ThisDrawing.Dictionaries
If oDict.Name = "MyDictionary" Then
DoSomething
End If
Next

It seems that the Dictionaries collection contains a couple of Items
which
don't have a name.or even show up as dictionaries.

The code below runs without error.

For i = 5 to ThisDrawing.Dictionaries.Count
If ThisDrawing.Dictionaries.Item(i).Name = "MyDictionary" Then
Do Something
End If
Next

At the moment I'm working in Land Desktop R3 and my drawing has 26
dictionaries. Is this normal? Roughly how many default dictionaries do
you
find in a standard AutoCAD drawing.

The following code works in respect of finding my dictionary:

On Error Resume Next
Set oDict = ThisDrawing.Dictionaries.Item("MyDictionary")
If Err <> 0 Then
MsgBox "You haven't created this dictionary yet"
End If

I found this in the help file:
"Dictionaries: The return value type for this method is IAcadObject.
This
allows you to retrieve named objects from the dictionaries collection
that
are not of the type AcadDictionary. "

Does this mean that the first code segment could be made to work by
using a
TypeOf test along the lines below:

Dim oDict As Object
For Each oDict in ThisDrawing.Dictionaries
If TypeOf oDict Is AcadDictionary Then
If oDict.Name = "MyDictionary" Then
DoSomething
End If
End If
Next
--


Laurie Comerford
CADApps
www.cadapps.com.au



Back to top
Tony Tanzillo
Guest





Posted: Mon Apr 04, 2005 1:03 am    Post subject: Re: Dictionaries collection Reply with quote

I won't give you a direct answer, but here are some
points to to consider:

1. Do you want to process only AcadDictionary objects,
or any object that supports the IAcadDictionary interface?
To do the latter, you have to use 'typeof IAcadDictionary',
which means that any type of object that supports that
interface will pass the test. I'm not sure if that also works
if you use 'typeof AcadDictionary' (note that you're using
a class type in this case, not an interface type).

2. Code clarity. Obviously, the error trapping approach does
not as clearly or explictily convey the intent, so that is a
ligitimate concern.

3. Unanticipated errors. With the error trapping approach,
you can either test the error condition explicitly to see if
it is the one you expect to occur when you try to assign
an object that doesn't support the AcadDictionary interface
to a variable dim'd as AcadDictionary, or you can assume
it was the expected error (as most do).

However, if there is a remote chance that another error
could also occur when you do the assignment, you would
need to explicitly test the error, rather than just assume
it was the one you expected.

Make up your own mind :-)

--
http://www.caddzone.com

AcadXTabs: MDI Document Tabs for AutoCAD 2004/2005/2006
http://www.acadxtabs.com

"Mark Propst" <NoSpam@HereThanks.com> wrote in message news:424f3ef2_3@newsprd01...
Quote:
Hi Tony,
I'd be interested to know if you have a preference for either of the two
ways which both "work".
From the standpoint of a criteria of professionalism in programming, - or
just doing it the 'right' way -
would there be a reason to prefer one over the other?
1) the error trapping method
or
2) the type-testing method
:-)
Mark

"Tony Tanzillo" <tony.tanzillo@U_KNOW_WHERE.com> wrote in message
news:424ebdcd$1_3@newsprd01...
Right. A dictionary (which is what the dictionaries collection
itself is), can contain any object derived from AcadObject, so
you can't assume that everything in the collection is an
AcadDictionary.

You can either use typeof, or just try to assign each item
to a variable dim'd as AcadDictionary, and trap the error
that occurs if its not an AcadDictionary.

--
http://www.caddzone.com

AcadXTabs: MDI Document Tabs for AutoCAD 2004/2005/2006
http://www.acadxtabs.com

"Laurie Comerford" <laurie@DeleteThiscadapps.com.au> wrote in message
news:424e42c6_1@newsprd01...
Hi,

I have been experimenting with using the dictionaries collection as a
means
of storing data in a drawing.

The following code is creating an error.

Dim oDict As AcadDictionary

For Each oDict in ThisDrawing.Dictionaries
If oDict.Name = "MyDictionary" Then
DoSomething
End If
Next

It seems that the Dictionaries collection contains a couple of Items
which
don't have a name.or even show up as dictionaries.

The code below runs without error.

For i = 5 to ThisDrawing.Dictionaries.Count
If ThisDrawing.Dictionaries.Item(i).Name = "MyDictionary" Then
Do Something
End If
Next

At the moment I'm working in Land Desktop R3 and my drawing has 26
dictionaries. Is this normal? Roughly how many default dictionaries do
you
find in a standard AutoCAD drawing.

The following code works in respect of finding my dictionary:

On Error Resume Next
Set oDict = ThisDrawing.Dictionaries.Item("MyDictionary")
If Err <> 0 Then
MsgBox "You haven't created this dictionary yet"
End If

I found this in the help file:
"Dictionaries: The return value type for this method is IAcadObject.
This
allows you to retrieve named objects from the dictionaries collection
that
are not of the type AcadDictionary. "

Does this mean that the first code segment could be made to work by
using a
TypeOf test along the lines below:

Dim oDict As Object
For Each oDict in ThisDrawing.Dictionaries
If TypeOf oDict Is AcadDictionary Then
If oDict.Name = "MyDictionary" Then
DoSomething
End If
End If
Next
--


Laurie Comerford
CADApps
www.cadapps.com.au





Back to top
MP
Guest





Posted: Mon Apr 04, 2005 6:11 am    Post subject: Re: Dictionaries collection Reply with quote

Thanks
:-)

"Tony Tanzillo" <tony.tanzillo@U_KNOW_WHERE.com> wrote in message
news:42505a09$1_3@newsprd01...
Quote:
I won't give you a direct answer, but here are some
points to to consider:


Make up your own mind :-)
Back to top
 
Post new topic   Reply to topic    CADForums.net Forum Index -> VBA All times are GMT
Page 1 of 1

 
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum




Windows Server DSP VoIP Electronics New Topics
Powered by phpBB