.NET

Reply
Contributor
tbrammer
Posts: 23
Registered: ‎07-20-2011
Message 1 of 7 (351 Views)
Accepted Solution

How to get AcadApplication from a C# assembly running in AutoCAD OEM?

351 Views, 6 Replies
05-28-2014 06:02 AM

The following C# code works under AutoCAD (2013/14) and crashes under AutoCAD OEM 2013:

 

 

dynamic acadApp = Autodesk.AutoCAD.ApplicationServices.Application.AcadApplication;
dynamic preferences = acadApp.Preferences; //OK in AutoCAD. Crash in AutoCAD OEM

 

I suppose the OEM crashes, because it doesn’t expose the AcadApplication  COM interface. Am I right?

In C++ I can get the OEM’s IAcadApplication Interface when I am in an ARX that is running in acad’s / oem’s address space:

 

CWinApp *pApp = acedGetAcadWinApp();
IAcadApplication *pIAcad = (IAcadApplication*)pApp->GetIDispatch(TRUE);

Is there a similar way to get the AcadApplication in C# that works in CAD _and_ OEM?

 

--Thomas

The Interop dll's are available in the AutoCAD OEM specific ObjectARX as well, even though the ActiveX object model isn't exposed in AutoCAD OEM in a similar way that vanilla AutoCAD..

I tried with AutoCAD OEM 2014 without the dynamic types that you had:

 

                       AcadApplication acadapp = (AcadApplication)Application.AcadApplication;
                       AcadPreferences preferences = (AcadPreferences)acadapp.Preferences;

 

I also tried referencing the TLB's from Inc-x64, it works fine too:

 

                      AutoCAD.AcadApplication acadapp = (AutoCAD.AcadApplication)Application.AcadApplication;

                      AutoCAD.AcadPreferences preferences = (AutoCAD.AcadPreferences)acadapp.Preferences;

 

 

Maybe, Balaji can throw some light on why 'dynamic' wouldn't work in the OEM environment?

 

Cheers,

Paavo

 

ADN Support Specialist
Balaji_Ram
Posts: 715
Registered: ‎03-21-2011
Message 2 of 7 (314 Views)

Re: How to get AcadApplication from a C# assembly running in AutoCAD OEM?

05-28-2014 08:47 AM in reply to: tbrammer

Sorry, I deleted my previous reply to this post.

 

I will need to look into your query more closely.



Balaji
Developer Technical Services
Autodesk Developer Network

Active Member
paavo
Posts: 9
Registered: ‎05-19-2014
Message 3 of 7 (304 Views)

Re: How to get AcadApplication from a C# assembly running in AutoCAD OEM?

05-28-2014 11:05 AM in reply to: Balaji_Ram

The Interop dll's are available in the AutoCAD OEM specific ObjectARX as well, even though the ActiveX object model isn't exposed in AutoCAD OEM in a similar way that vanilla AutoCAD..

I tried with AutoCAD OEM 2014 without the dynamic types that you had:

 

                       AcadApplication acadapp = (AcadApplication)Application.AcadApplication;
                       AcadPreferences preferences = (AcadPreferences)acadapp.Preferences;

 

I also tried referencing the TLB's from Inc-x64, it works fine too:

 

                      AutoCAD.AcadApplication acadapp = (AutoCAD.AcadApplication)Application.AcadApplication;

                      AutoCAD.AcadPreferences preferences = (AutoCAD.AcadPreferences)acadapp.Preferences;

 

 

Maybe, Balaji can throw some light on why 'dynamic' wouldn't work in the OEM environment?

 

Cheers,

Paavo

 

Contributor
tbrammer
Posts: 23
Registered: ‎07-20-2011
Message 4 of 7 (254 Views)

Re: How to get AcadApplication from a C# assembly running in AutoCAD OEM?

06-02-2014 01:24 AM in reply to: paavo

Thanks paavo!

 

Changing 'dynamic' to 'AutoCAD.AcadApplication' really does the trick!

I didn't even know the that acadapp's class is  'AutoCAD.AcadApplication' because docs and headers ony say it is an 'object' :-(.

I had to reference 'AutoCAD' from <oem>\arx\inc-x64\acax19ENU.tlb  in my project to make it compileable.

But even with the reference to 'AutoCAD' the code only works with explicit casting to 'AutoCAD.AcadApplication' in OEM.

 

@Balaji_Ram :

(a) Can you confirm that it is safe to use AcadApplication in the OEM like this?

(b) Why doesn't 'dynamic' work in OEM?

 

--Thomas

 

 

 

 

 

ADN Support Specialist
Balaji_Ram
Posts: 715
Registered: ‎03-21-2011
Message 5 of 7 (213 Views)

Re: How to get AcadApplication from a C# assembly running in AutoCAD OEM?

06-04-2014 10:56 AM in reply to: tbrammer

Hi Thomas,

 

 

From the reply that I received from our engineering team, AutoCAD OEM intentionally puts some restrictions on using dynamic keyword due to certain licensing checks in OEM with which the dynamic keyword was interfering.

 

About using the interop assemblies - Yes, that should work ok. The interop assemblies are found in the Arx sub folder in the OEM install folder. You do not need the tlb to be referenced.

 

Regards,

Balaji



Balaji
Developer Technical Services
Autodesk Developer Network

Contributor
tbrammer
Posts: 23
Registered: ‎07-20-2011
Message 6 of 7 (186 Views)

Re: How to get AcadApplication from a C# assembly running in AutoCAD OEM?

06-05-2014 01:25 AM in reply to: Balaji_Ram

Hi Balaji,

 

thanks for the clarification.

 

I think this difference between AutoCAD and AutoCAD OEM should be mentioned in the OEM developers guide (oemdev) in the

“How Do AutoCAD and AutoCAD OEM differ?” section.

 

Beside that I think the documentation of   Autodesk.AutoCAD.ApplicationServices.Application   is insufficient.

The only description of the Application.AcadApplication Property in the "Managed Class Referece" is this:

 

  C#: public static object AcadApplication;
  VB: Public static Property AcadApplication() As object
  Description: Accesses the AcadApplication.
  Conditions: Read-only

 

How am I supposed to find out that the object represents an  AutoCAD.AcadApplication ?

And where is AutoCAD.AcadApplication documented?

(I have to admit that I'm more a C++ than an C# expert.)

 

--Thomas

 

 

ADN Support Specialist
Balaji_Ram
Posts: 715
Registered: ‎03-21-2011
Message 7 of 7 (183 Views)

Re: How to get AcadApplication from a C# assembly running in AutoCAD OEM?

06-05-2014 01:46 AM in reply to: tbrammer

"...should be mentioned in the OEM developers guide (oemdev) in the “How Do AutoCAD and AutoCAD OEM differ?” section."

 

I will inform the documentation team to get this change.

 

"How am I supposed to find out that the object represents an  AutoCAD.AcadApplication ?"

 

I do not have an answer to that.

The way I get them is to find a class with the same name in the COM API documentation.

 

"And where is AutoCAD.AcadApplication documented?"

 

For a documentation of the COM API, you will need to refer to the ActiveX API documentation that is part of AutoCAD help.

 

Regards,

Balaji

 



Balaji
Developer Technical Services
Autodesk Developer Network

Post to the Community

Have questions about Autodesk products? Ask the community.

New Post
Need installation help?

Start with some of our most frequented solutions or visit the Installation and Licensing Forum to get help installing your software.