Interop Activex or .NET API? Which one is recommended?

Interop Activex or .NET API? Which one is recommended?

apoorva_jukanti
Participant Participant
2,078 Views
20 Replies
Message 1 of 21

Interop Activex or .NET API? Which one is recommended?

apoorva_jukanti
Participant
Participant

Hi,

 

My requirement is migrating a desktop application from .vbp to .net. 

Present code in vb is using ActiveX object to launch the autocad application and insert blocks and deal with the block attributes. The major existing project is to use the existing drawing blocks in specific path and modify and replace them.

 

Now while migrating it to .net which is the optimized way(recommended waY) to implement the above mentioned functionality, ActiveX or Autocad .Net API?

Please suggest a viable solution.

0 Likes
Accepted solutions (2)
2,079 Views
20 Replies
Replies (20)
Message 2 of 21

_gile
Consultant
Consultant
Accepted solution

Hi,

The .NET API is more powerfull but it cannot be directly used as stand-alone executable (exe). See this topic.



Gilles Chanteau
Programmation AutoCAD LISP/.NET
GileCAD
GitHub

0 Likes
Message 3 of 21

apoorva_jukanti
Participant
Participant

Can you please provide examples of using ActiveX Interop  in C# other than launching autocad application ?  For Example: InsertBlock Method(ActiveX) 

0 Likes
Message 4 of 21

apoorva_jukanti
Participant
Participant

Is there any possibility of Deprecating ActiveX in future?

As Microsoft might stop supporting VB in future?

 

0 Likes
Message 5 of 21

_gile
Consultant
Consultant

@apoorva_jukanti  a écrit :

Can you please provide examples of using ActiveX Interop  in C# other than launching autocad application ?  For Example: InsertBlock Method(ActiveX) 


If you absolutely want to use ActiveX Interop in a .NET plugin (which most AutoCAD .NET developers deprecate), you can simply get the the AcadApplication object from the Application.AcadApplication property.

var acadApp = (AcadApplication)Application.AcadApplication;
var thisDrawing = acadApp.ActiveDocument;
var blockRef = thisDrawing.ModelSpace.InsertBlock(Point3d.Origin.ToArray(), blockName, 1.0, 1.0, 1.0, 0.0);


Gilles Chanteau
Programmation AutoCAD LISP/.NET
GileCAD
GitHub

0 Likes
Message 6 of 21

apoorva_jukanti
Participant
Participant

No, I would like to use .Net API.

But, My requirement is launching autocad from .net (which can be done only using ActiveX) and then use the existing .dwg from a folder and modify them.

 

Can I use ActiveX object for launching Autocad and then use .Net api for modifying the drawing ?

0 Likes
Message 7 of 21

_gile
Consultant
Consultant

@apoorva_jukanti  a écrit :

No, I would like to use .Net API.

But, My requirement is launching autocad from .net (which can be done only using ActiveX) and then use the existing .dwg from a folder and modify them.

 

Can I use ActiveX object for launching Autocad and then use .Net api for modifying the drawing ?


You can use the same "ConnectToAcad" method of the example in this topic from a stand-alone executable (without the CommandMethodAttribute).



Gilles Chanteau
Programmation AutoCAD LISP/.NET
GileCAD
GitHub

0 Likes
Message 8 of 21

apoorva_jukanti
Participant
Participant

Can you please tell the valid nuget for using Interop.AutoCAD.dll

0 Likes
Message 9 of 21

_gile
Consultant
Consultant

https://www.nuget.org/packages/AutoCAD.NET.Interop



Gilles Chanteau
Programmation AutoCAD LISP/.NET
GileCAD
GitHub

0 Likes
Message 10 of 21

apoorva_jukanti
Participant
Participant

if I install the latest autocad 2025 nuget, i will be able to use lower versions of autocad also right?

0 Likes
Message 11 of 21

apoorva_jukanti
Participant
Participant

apoorva_jukanti_0-1725620298498.png

it shows it does not support 

0 Likes
Message 12 of 21

_gile
Consultant
Consultant

@apoorva_jukanti  a écrit :

if I install the latest autocad 2025 nuget, i will be able to use lower versions of autocad also right?


No. You have to install the package corresponding to the targeted AutoCAD version.



Gilles Chanteau
Programmation AutoCAD LISP/.NET
GileCAD
GitHub

0 Likes
Message 13 of 21

kerry_w_brown
Advisor
Advisor
Accepted solution

@apoorva_jukanti wrote:

apoorva_jukanti_0-1725620298498.png

it shows it does not support 


//

the wording is "provide support"

That means that nuget won't answer questions about the files provided . . . which I think is typical, they just push the files provided by their clients.
sort of like : don't complain to the postman about the bills you get in the mail.


// Called Kerry or kdub in my other life.

Everything will work just as you expect it to, unless your expectations are incorrect. ~ kdub
Sometimes the question is more important than the answer. ~ kdub

NZST UTC+12 : class keyThumper<T> : Lazy<T>;      another  Swamper
0 Likes
Message 14 of 21

apoorva_jukanti
Participant
Participant

Is there a way, I can support all versions of autocad? using the AutoCAD.NET.Interop NuGet in my c# code

 

0 Likes
Message 15 of 21

apoorva_jukanti
Participant
Participant

Can you please provide nuget that supports .net framework4.8 and autocad 2025

0 Likes
Message 16 of 21

_gile
Consultant
Consultant

As said upper the COM API is not version compatible.

You have to build separated assembies for each targeted AutoCAD version (at least major version) referencing the corresponding libraries.

.



Gilles Chanteau
Programmation AutoCAD LISP/.NET
GileCAD
GitHub

0 Likes
Message 17 of 21

norman.yuan
Mentor
Mentor

@apoorva_jukanti 

Judging by the questions you asked here and in the other forum (ObjectARX), it seems to me that you are probably not very familiar with AutoCAD programming and the various types of AutoCAD APIs that could be used in different scenarios/application types.

 

You might as well provide some detailed description of what type of application you want to develop, some business requirements/workflows...because these things decide if your goal is doable, and if yes, what AutoCAD API should be used. At least people do not have to keep guessing an answer you really want to hear.

 

Norman Yuan

Drive CAD With Code

EESignature

0 Likes
Message 18 of 21

daniel_cadext
Advisor
Advisor

Yes, you can use late binding and dynamic coding styles, this will eliminate the need for hard references.

Python for AutoCAD, Python wrappers for ARX https://github.com/CEXT-Dan/PyRx
0 Likes
Message 19 of 21

JPR_INTT
Observer
Observer

Hey everyone, this is the closest topic I've founded related to my situation. I'm creating a revit plugin, but I'd like it to retrieve some geometry from AutoCAD, so is it possible doing with .NET or only ActiveX?
Actually, I have a button on the revit form, when I click the button, I need to select a polyline in AutoCAD to get the points.

0 Likes
Message 20 of 21

norman.yuan
Mentor
Mentor

When you say "...need to select a polyline in AutoCAD to get the points...", by "select", do you mean the user HAS TO manually/interactively select an Acad entity in AutoCAD's editor (i.e. running AutoCAD session's drawing editing window)? If so, since the selecting process is initiated from within Revit, yes, you have to use AutoCAD COM/ActiveX API to do it.

 

In general, this would be an quite awkward operation, because the user has to switch attention between 2 heavy desktop apps. IMO, I would try to avoid it as much as possible.

 

If the target entity or entities in a drawing file can somehow be identified by code (say, by creating the drawing contents following a set of well-defined CAD standards), then this "going-to-another-running-app-for-selecting" thing would be avoided, and you could be spared from relying on running 2 heavy desktop apps side by side and switching user's attention back and forth.

 

Norman Yuan

Drive CAD With Code

EESignature

0 Likes