Author Topic: Get unmanaged class name  (Read 4611 times)

0 Members and 1 Guest are viewing this topic.

Andrey Bushman

  • Swamp Rat
  • Posts: 864
Get unmanaged class name
« on: October 08, 2011, 05:02:05 AM »
Hi all.

I write 2 methods:
Code: [Select]
    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.

kaefer

  • Guest
Re: Get unmanaged class name
« Reply #1 on: October 08, 2011, 06:25:09 AM »
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:
Code: [Select]
        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:
Quote
ArcDimension -> AcDbArcDimension
AcDbArcDimension -> ArcDimension

Andrey Bushman

  • Swamp Rat
  • Posts: 864
Re: Get unmanaged class name
« Reply #2 on: October 08, 2011, 07:50:46 AM »
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:
Code: [Select]
        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:
Quote
ArcDimension -> AcDbArcDimension
AcDbArcDimension -> ArcDimension
Thank you!