TheSwamp
Code Red => .NET => Topic started by: Andrey Bushman on October 08, 2011, 05:02:05 AM
-
Hi all.
I write 2 methods:
public static class AcEnvironment {
public static Type GetWrappedType(string acadClassName) {
Type type = null;
RXObject rxObj = Autodesk.AutoCAD.Runtime.SystemObjects.ClassDictionary[acadClassName];
RXClass rxClass = rxObj as RXClass;
if (rxClass != null)
using (DBObject rx = (DBObject) rxClass.Create())
type = rx.GetType();
return type;
}
public static string GetClassName<T>() where T : DBObject, new() {
return new T().GetRXClass().Name;
}
}
But I have are problem with GetClassName<T> method: not all classes, inherited from DBObject, have a default constructor. For example - it is ArcDimension class.
How to rewrite method GetClassName that it was possible to receive a name of an unmanaged classes such as ArcDimension?
I while don't have ideas... :( There can be I invent a bicycle and it already is available in AutoCAD 2009 .Net API?
Thanks all.
-
I don't think that you need to construct a DBObject to have access to its RXClass. You can use the static RXObject.GetClass method instead.
Demonstration:
let t = typeof<ArcDimension>
ed.WriteMessage("\n{0} -> {1} ", t.Name, RXObject.GetClass(t).Name)
let rx = SystemObjects.ClassDictionary.["AcDbArcDimension"] :?> RXClass
use dbo = rx.Create()
ed.WriteMessage("\n{0} -> {1} ", rx.Name, dbo.GetType().Name)
Output:
ArcDimension -> AcDbArcDimension
AcDbArcDimension -> ArcDimension
-
I don't think that you need to construct a DBObject to have access to its RXClass. You can use the static RXObject.GetClass method instead.
Demonstration:
let t = typeof<ArcDimension>
ed.WriteMessage("\n{0} -> {1} ", t.Name, RXObject.GetClass(t).Name)
let rx = SystemObjects.ClassDictionary.["AcDbArcDimension"] :?> RXClass
use dbo = rx.Create()
ed.WriteMessage("\n{0} -> {1} ", rx.Name, dbo.GetType().Name)
Output:
ArcDimension -> AcDbArcDimension
AcDbArcDimension -> ArcDimension
Thank you!