Author Topic: Creating Dictionary<AcRtm.RXClass, Type>  (Read 7813 times)

0 Members and 1 Guest are viewing this topic.

Andrey Bushman

  • Swamp Rat
  • Posts: 864
Creating Dictionary<AcRtm.RXClass, Type>
« on: August 17, 2012, 02:38:57 AM »
Hi all.

Data:
AutoCAD 2009 SP3 Enu x86,
Windows XP SP3 x86
.Net Framework 3.5 SP1

I want to create Dictionary<AcRtm.RXClass, Type> for more quickly to define managed types for RXClasses. I wrote it code:
Code: [Select]
Dictionary<AcRtm.RXClass, Type> mngTypeDict = new Dictionary<AcRtm.RXClass, Type>();

//Names of RXClasses, which do not have manage wrapper.
StringBuilder sb = new StringBuilder();

foreach (DictionaryEntry item in AcRtm.SystemObjects.ClassDictionary) {
AcRtm.RXClass rx;
Type type;
AcRtm.RXObject obj;

try {
rx = (AcRtm.RXClass)item.Value;
obj = rx.Create();

if (obj != null) {
type = obj.GetType();
mngTypeDict.Add(rx, type);
}
else
sb.AppendLine(rx.Name);
}
catch (Exception ex) {
//oops..
}
}

But I get Fatall Error (try/catch doesn't help even):
Quote
INTERNAL ERROR:  !dbAnnotationScaleCollectioni.cpp@37: eNullObjectPointer

Regards

MexicanCustard

  • Swamp Rat
  • Posts: 705
Re: Creating Dictionary<AcRtm.RXClass, Type>
« Reply #1 on: August 17, 2012, 07:29:21 AM »

What line of the code is execution crashing?
Revit 2019, AMEP 2019 64bit Win 10

Andrey Bushman

  • Swamp Rat
  • Posts: 864
Re: Creating Dictionary<AcRtm.RXClass, Type>
« Reply #2 on: August 17, 2012, 07:43:28 AM »
obj = rx.Create();

MexicanCustard

  • Swamp Rat
  • Posts: 705
Re: Creating Dictionary<AcRtm.RXClass, Type>
« Reply #3 on: August 17, 2012, 10:37:22 AM »
I apologize if AcRtm is an AutoCAD class but I cannot find anything documenting it. Is this a custom class?

Edit:
Nevermind I see from another thread that you're using it as an alias for Autodesk.AutoCAD.Runtime.

I'd try
Code: [Select]
var rx = item.value as AcRtm.RXClass
if (rx != null)
  obj = rx.Create();

« Last Edit: August 17, 2012, 10:45:47 AM by MexicanCustard »
Revit 2019, AMEP 2019 64bit Win 10

Andrey Bushman

  • Swamp Rat
  • Posts: 864
Re: Creating Dictionary<AcRtm.RXClass, Type>
« Reply #4 on: August 17, 2012, 10:46:15 AM »
I apologize if AcRtm is an AutoCAD class but I cannot find anything documenting it. Is this a custom class?
No, it is namespace: using AcRtm = Autodesk.AutoCAD.Runtime;

MexicanCustard

  • Swamp Rat
  • Posts: 705
Re: Creating Dictionary<AcRtm.RXClass, Type>
« Reply #5 on: August 20, 2012, 07:56:45 AM »
Autodesk.AutoCAD.Runtime is the namespace

AcRtm is an alias you're using to represent that namespace.
Revit 2019, AMEP 2019 64bit Win 10

fixo

  • Guest
Re: Creating Dictionary<AcRtm.RXClass, Type>
« Reply #6 on: August 20, 2012, 08:37:31 AM »
Perhaps
Code: [Select]
obj = rx.Create(IntPtr.Zero);Or I'm missing something above, so, sorry

~'J'~

MexicanCustard

  • Swamp Rat
  • Posts: 705
Re: Creating Dictionary<AcRtm.RXClass, Type>
« Reply #7 on: August 20, 2012, 12:30:34 PM »
I didn't see it in the documentation but with Object Browser

Autodesk.AutoCAD.Runtime.DisposableWrapper.Create(System.Type, System.IntPtr, bool)
Autodesk.AutoCAD.Runtime.RXObject.Create(System.IntPtr, bool)
« Last Edit: August 20, 2012, 12:34:19 PM by MexicanCustard »
Revit 2019, AMEP 2019 64bit Win 10

Jeff H

  • Needs a day job
  • Posts: 6150
Re: Creating Dictionary<AcRtm.RXClass, Type>
« Reply #8 on: August 20, 2012, 08:29:00 PM »
I am just guessing but you might need to filiter for objects because you will probably get a bunch of Imp****** objects.
 
Not sure what you are doing but you looks like you would still need iterate through dictionary and use a property of RxClasss to be able compare.
 
Some untested code?
Code - C#: [Select]
  1.  
  2.          [CommandMethod("RxclassTypes")]
  3.         public void RxclassTypes()
  4.         {
  5.             Document doc = Application.DocumentManager.MdiActiveDocument;
  6.             Database db = doc.Database;
  7.             Editor ed = doc.Editor;
  8.             Dictionary<RXClass, Type> dic = new Dictionary<RXClass, Type>();
  9.                 RXClass rxEntity = RXClass.GetClass(typeof(Entity));
  10.                 foreach (DictionaryEntry e in SystemObjects.ClassDictionary)
  11.                 {
  12.                     RXClass rxclass = e.Value as RXClass;
  13.                     if (rxclass.IsDerivedFrom(rxEntity))
  14.                     {                                      
  15.                         Type type = rxclass.GetRuntimeType();                    
  16.                         dic.Add(rxclass, type);
  17.                     }
  18.                 }
  19.        
  20.         }
  21.  

Andrey Bushman

  • Swamp Rat
  • Posts: 864
Re: Creating Dictionary<AcRtm.RXClass, Type>
« Reply #9 on: August 22, 2012, 03:48:12 AM »
Autodesk.AutoCAD.Runtime is the namespace

AcRtm is an alias you're using to represent that namespace.
Yes, I wrote it in my last message.

Andrey Bushman

  • Swamp Rat
  • Posts: 864
Re: Creating Dictionary<AcRtm.RXClass, Type>
« Reply #10 on: August 22, 2012, 04:27:38 AM »
I didn't see it in the documentation but with Object Browser

Code - C#: [Select]
  1. Autodesk.AutoCAD.Runtime.DisposableWrapper.Create(System.Type, System.IntPtr, bool)
  2. Autodesk.AutoCAD.Runtime.RXObject.Create(System.IntPtr, bool)
It is very interesting. But AutoCAD 2009 .Net API has
Code - C#: [Select]
  1. Autodesk.AutoCAD.Runtime.DisposableWrapper.Create(System.Type, System.IntPtr, bool)
only. :(

I tried to get wrapper:
Code - C#: [Select]
  1. Dictionary<RXClass, Type> mngTypeDict = new Dictionary<RXClass, Type>();
  2.  
  3. foreach (DictionaryEntry item in SystemObjects.ClassDictionary) {
  4.         RXClass rx;
  5.         Type type;
  6.         try {
  7.                 rx = (RXClass)item.Value;
  8.                 IntPtr ptr = rx.UnmanagedObject;               
  9.                 DisposableWrapper wrap = Autodesk.AutoCAD.Runtime.DisposableWrapper.Create(typeof(Object), ptr, false);
  10.                 type = wrap.GetType();                                 
  11.         }
  12.         catch (Exception ex) {
  13.                 //oops..
  14.         }
  15. }
  16.  
but I got error:
Quote
Constructor on type 'System.Object' not found.

Andrey Bushman

  • Swamp Rat
  • Posts: 864
Re: Creating Dictionary<AcRtm.RXClass, Type>
« Reply #11 on: August 22, 2012, 04:35:03 AM »
Some untested code?
Code - C#: [Select]
  1.  
  2. ...                                
  3. Type type = rxclass.GetRuntimeType();                    
  4. ...
  5.  
Sorry, but AutoCAD 2009 .Net API has not GetRuntimeType method for RXClass class. :(

Andrey Bushman

  • Swamp Rat
  • Posts: 864
Re: Creating Dictionary<AcRtm.RXClass, Type>
« Reply #12 on: August 22, 2012, 04:56:00 AM »
Am I inventing a bicycle, maybe? I need to get wrapper type for each RXClass in Database. Is exists a simple and fast (for speed) solution to do it?
« Last Edit: August 22, 2012, 05:03:50 AM by Andrey »

TheMaster

  • Guest
Re: Creating Dictionary<AcRtm.RXClass, Type>
« Reply #13 on: August 22, 2012, 07:30:37 AM »
Am I inventing a bicycle, maybe? I need to get wrapper type for each RXClass in Database. Is exists a simple and fast (for speed) solution to do it?

Before AutoCAD 2013, the only way was to create an instance of the wrapper class, and even that wasn't foolproof if the native ARX that provides it is not available (then an ImpDBObject wrapper is created).

In AutoCAD 2013, RXClass has a new method that returns the managed wrapper type.

Andrey Bushman

  • Swamp Rat
  • Posts: 864
Re: Creating Dictionary<AcRtm.RXClass, Type>
« Reply #14 on: August 22, 2012, 12:03:24 PM »
Before AutoCAD 2013, the only way was to create an instance of the wrapper class, and even that wasn't foolproof if the native ARX that provides it is not available (then an ImpDBObject wrapper is created).

In AutoCAD 2013, RXClass has a new method that returns the managed wrapper type.
Thank you for answer.