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 AG ● LinkedIn ●
If an answer solves your problem please [ACCEPT SOLUTION]. Otherwise explain why not.
Solved! Go to Solution.
Solved by techsoft3d. Go to Solution.
Sorry, I deleted my previous reply to this post.
I will need to look into your query more closely.
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
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
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
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
"...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
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