.NET
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

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

7 REPLIES 7
SOLVED
Reply
Message 1 of 8
tbrammer
7578 Views, 7 Replies

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

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


Thomas Brammer ● Software Developer ● imos AGLinkedIn
If an answer solves your problem please [ACCEPT SOLUTION]. Otherwise explain why not.

7 REPLIES 7
Message 2 of 8
Balaji_Ram
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

Message 3 of 8
techsoft3d
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

 

Message 4 of 8
tbrammer
in reply to: techsoft3d

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

 

 

 

 

 


Thomas Brammer ● Software Developer ● imos AGLinkedIn
If an answer solves your problem please [ACCEPT SOLUTION]. Otherwise explain why not.

Message 5 of 8
Balaji_Ram
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

Message 6 of 8
tbrammer
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

 

 


Thomas Brammer ● Software Developer ● imos AGLinkedIn
If an answer solves your problem please [ACCEPT SOLUTION]. Otherwise explain why not.

Message 7 of 8
Balaji_Ram
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

Message 8 of 8
kbarnettza
in reply to: Balaji_Ram

Downloaded Object ARX SDK 2018. Referenced : inc-x64\acax22ENU.TLB and inc-x64\axdb22enu.tlb

added:

Using AutoCAD;

I am able to start an instance of AutoCAD using:

AcadApplication acapp = new AcadApplication();

but I cannot figure out how to access an exiting instance of AutoCAD.

This line:

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

Is not valid ... Application does not contain a definition for AcadApplication

 

 

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Autodesk DevCon in Munich May 28-29th


Autodesk Design & Make Report

”Boost