Message 1 of 11
C#.NET and AutoCAD Dictionary objects.
Not applicable
10-10-2002
01:56 AM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
I have done some extensive work with Dictionaries (xRecords), and XData. I
have been able to replicate read/write of xData, and write of xrecords in
C#.NET. However, I have been able to read xrecords, or even open a
dictionary at all using .NET.
The problem is is the casting of types. Here is some code to add a
dictionary (works)...
source.AcadDocument.Dictionaries.Add(mstrDictName);
no problem, but here is what I am doing to get a reference to the dictionary
object...
=====================================================================
public static AutoCAD.AcadDictionaryClass Dictionary(ACAD.Document source)
{
//An Acad.Document object is a special object of mine which contains a
reference to an
// AutoCAD "AcadDocumentClass" object.
AutoCAD.AcadObject aoDict;
AutoCAD.AcadDictionaryClass adDict;
try
{
aoDict = source.AcadDocument.Dictionaries.Item(mstrDictName);
if (aoDict != null)
{
//adDict = (AutoCAD.AcadDictionaryClass)aoDict; //(doesn't work)
//adDict = aoDict as AutoCAD.AcadDictionaryClass; //(doesn't work)
object oD = source.AcadDocument.HandleToObject(aoDict.Handle);
//HandleToObject returns an "AcadObject" type.
adDict = oD as AutoCAD.AcadDictionaryClass; //doesn't work
return adDict;
}
else
{// does not exist in this document.
return null;
}
}
catch (Exception ex)
{
throw new InvalidOperationException("Problem reading Boundary Dictionary
from AutoCAD.", ex);
}
}
=====================================================================
As you can see i tried 3 ways. The problem is that the original object
returned from the indexer of the dictionaries collection is an "AcadObject".
First of all, it should return an AcadDictionary. How could the
Dictionaries collection contain anything but a Dictionary? It probably is
just another problem with the auto-generated wrapper. Although I am
currently using the wrapper from AcadX (www.acadx.com) which fixes the event
bug in the auto-generated wrapper.
It seems none of the 3 ways of casting to a dictionary from an AcadObject
works. Anyone have any other ideas? I have trouble casting from any
AutoCAD type to any other AutoCAD type actually... IE. AcadEntity to
AcadArc or AcadLine...
Michael
have been able to replicate read/write of xData, and write of xrecords in
C#.NET. However, I have been able to read xrecords, or even open a
dictionary at all using .NET.
The problem is is the casting of types. Here is some code to add a
dictionary (works)...
source.AcadDocument.Dictionaries.Add(mstrDictName);
no problem, but here is what I am doing to get a reference to the dictionary
object...
=====================================================================
public static AutoCAD.AcadDictionaryClass Dictionary(ACAD.Document source)
{
//An Acad.Document object is a special object of mine which contains a
reference to an
// AutoCAD "AcadDocumentClass" object.
AutoCAD.AcadObject aoDict;
AutoCAD.AcadDictionaryClass adDict;
try
{
aoDict = source.AcadDocument.Dictionaries.Item(mstrDictName);
if (aoDict != null)
{
//adDict = (AutoCAD.AcadDictionaryClass)aoDict; //(doesn't work)
//adDict = aoDict as AutoCAD.AcadDictionaryClass; //(doesn't work)
object oD = source.AcadDocument.HandleToObject(aoDict.Handle);
//HandleToObject returns an "AcadObject" type.
adDict = oD as AutoCAD.AcadDictionaryClass; //doesn't work
return adDict;
}
else
{// does not exist in this document.
return null;
}
}
catch (Exception ex)
{
throw new InvalidOperationException("Problem reading Boundary Dictionary
from AutoCAD.", ex);
}
}
=====================================================================
As you can see i tried 3 ways. The problem is that the original object
returned from the indexer of the dictionaries collection is an "AcadObject".
First of all, it should return an AcadDictionary. How could the
Dictionaries collection contain anything but a Dictionary? It probably is
just another problem with the auto-generated wrapper. Although I am
currently using the wrapper from AcadX (www.acadx.com) which fixes the event
bug in the auto-generated wrapper.
It seems none of the 3 ways of casting to a dictionary from an AcadObject
works. Anyone have any other ideas? I have trouble casting from any
AutoCAD type to any other AutoCAD type actually... IE. AcadEntity to
AcadArc or AcadLine...
Michael