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!
Solved! Go to Solution.
Solved by mcicognani. Go to Solution.
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,
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");