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

How to instantiate AutoCAD Mechanical AcadmApplication object?

2 REPLIES 2
SOLVED
Reply
Message 1 of 3
mcicognani
777 Views, 2 Replies

How to instantiate AutoCAD Mechanical AcadmApplication object?

Hi everybody,

I've found a few example in VB.NET, but none in C#. It shouldn't be that difficult, but I cannot instantiate the Mechanical application object...

 

I added to the project a reference to AutoCAD Mechanical 3.0 Type library, and the documentation says that it's a global symbol, but I'm not able to use it. I tried different initialization/casting from the Application.AcadApplication COM object, but with no result.

 

Has anyone a working example of an ACADM application in C#?

 

Thank you!

 

2 REPLIES 2
Message 2 of 3
adam.nagy
in reply to: mcicognani

Hi,

 

Whether it's VB, C# or other, in all cases you need to call

GetInterfaceObject

of the AutoCAD Application object to get it - like in this example:

http://adndevblog.typepad.com/manufacturing/2013/11/create-title-border-in-autocad-mechanical.html

 

Cheers,



Adam Nagy
Autodesk Platform Services
Message 3 of 3
mcicognani
in reply to: adam.nagy

That was one of the things I tried but since I got errors (Error 3: One or more types required to compile a dynamic expression cannot be found) I thought wasn't the right direction.

Since you confirmed this should work, I finally discovered the error: you need to manually add a reference to Microsoft.CSharp assembly.

It's out of my reach why a NET C# project do not reference the Microsoft.CSharp assemby by default, however, this does the trick.

For your reference I'm using Visual Studio 2013.

 

So, for future readers, in a NET C# project, to be able to reach the AcadmApplication object, you need to:

- reference AutoCAD 2015 Type Library to reach AcadApplication object;

- reference Autodesk AutoCAD Mechanical 3.0 Type Library to reach AcadmApplication object;

- reference Microsoft.CSharp to allow for dynamic expressions;

 

The code would be something like this:

 

// get the AcadApplication COM object
AutoCAD.AcadApplication mAcadApp = (AutoCAD.AcadApplication)Application.AcadApplication;
// get the AcadmApplication object AcadmAuto.AcadmApplication mAcmApp = (AcadmAuto.AcadmApplication)mAcadApp.GetInterfaceObject("AcadmAuto.AcadmApplication"); 

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