Connect to different version of AutoCAD

Connect to different version of AutoCAD

BestFriendCZ
Advocate Advocate
1,707 Views
2 Replies
Message 1 of 3

Connect to different version of AutoCAD

BestFriendCZ
Advocate
Advocate

I have a computer where are installed two version of ACAD (2017/2020). There is external app which connects to ACAD. This APP has DLL from ACAD version 2017.

 

If is ACAD 2017 running and so

 

acadApp = (AcadApplication)Marshal.GetActiveObject("Autocad.Application");   - isn't null

acadApp = (AcadApplication)Marshal.GetActiveObject("Autocad.Application.21.0");   - isn't null

acadApp = (AcadApplication)Marshal.GetActiveObject("Autocad.Application.23.1");   -  null !!!!

 

 

If is ACAD 2020 running and so

 

acadApp = (AcadApplication)Marshal.GetActiveObject("Autocad.Application");   -  null

acadApp = (AcadApplication)Marshal.GetActiveObject("Autocad.Application.21.0");   - null

acadApp = (AcadApplication)Marshal.GetActiveObject("Autocad.Application.23.1");   -  null !!!!

 

when I connect to this app DLL from version 2020 and ACAD 2020 running

 

acadApp = (AcadApplication)Marshal.GetActiveObject("Autocad.Application");   -  isn't null

acadApp = (AcadApplication)Marshal.GetActiveObject("Autocad.Application.21.0");   - null

acadApp = (AcadApplication)Marshal.GetActiveObject("Autocad.Application.23.1");   -  isn't null

 

DLL which is used

Autodesk.AutoCAD.Interop

Autodesk.AutoCAD.Interop.Common

 

I would like to know if exist any way how to connect to different versions of AUTOCAD. I mean doesn't matter which version running just connect to running instances

...
0 Likes
Accepted solutions (1)
1,708 Views
2 Replies
Replies (2)
Message 2 of 3

_gile
Consultant
Consultant
Accepted solution

Hi,

 

The COM libraries (Autodesk.AutoCAD.Interop and Autodesk.AutoCAD.Interop.Common) are version dependant. That means you must reference the 2017 libraries if you target AutoCAD 2017 and the 2019 or 2020 libraries if you target AutoCAD 2020.

One way to get rid of version dependence is to use late binding with the 'dynamic' type but this will make you lose the advantages of strong typing (intellisense and error detection at edition time).

dynamic acadApp = Marshal.GetActiveObject("Autocad.Application");

 

But, assuming AutoCAD is already runing, why not using the .NET API with a standard plugin (i.e. a DLL to be netloaded in AutoCAD)?

In my opinion, as far as you can, avoid using AutoCAD.Interop.



Gilles Chanteau
Programmation AutoCAD LISP/.NET
GileCAD
GitHub

0 Likes
Message 3 of 3

BestFriendCZ
Advocate
Advocate

Hi gile,

 

Thanks for your advice. I understand that use COM API is hell but on our company are lots of old Apps which using this type of API (thousand and thousand lines spaghetti code) and i have to support this old Apps too somehow…

...
0 Likes