Interop or .NET API?

Interop or .NET API?

Christopher.hartman
Enthusiast Enthusiast
5,292 Views
7 Replies
Message 1 of 8

Interop or .NET API?

Christopher.hartman
Enthusiast
Enthusiast

I am using two DLL's in my C# .NET application: interop.AutoCAD.dll and interop.AXDBLib.dll and I'm having trouble finding information on how to use these libraries.

 

Ultimately what I'm trying to accomplish is to create an API that takes in a template (DWT), adds a bunch of information from 2 different drawings (DWG) and saves the outcome to a network share.  However, I need to flesh out whether or not the Interop method is capable of doing this or if I need to switch to using the AutoCAD .NET API method.  The problem I ran into with that method is that I can't debug the code - something to do with "invalid application" error.

 

I'm new to AutoCAD and the AutoCAD API's and I don't know where to get reference material to show me how to use the API's so any help would be greatly appreciated.

0 Likes
Accepted solutions (2)
5,293 Views
7 Replies
Replies (7)
Message 2 of 8

_gile
Consultant
Consultant

Hi,

You should have a look at this page.

Specifically ActiveX: Developer's Guide and ActiveX: Reference Guide if you want to use the COM/Interop API or the ObjectARX: Managed .NET Develeoper's Guide and ObjectARX: Managed .NET Develeoper's Guide if you want to use the AutoCAD .NET API.



Gilles Chanteau
Programmation AutoCAD LISP/.NET
GileCAD
GitHub

0 Likes
Message 3 of 8

norman.yuan
Mentor
Mentor

Since you are "new to  AutoCAD...", I guess you are probably not only new to AutoCAD programming, but also have little experience as AutoCAD user. Besides asking which set of AutoCAD API to use - AutoCAD .NET, or Interop (should be AutoCAD COM API, wrapped with .NET interop, because you have to use .NET language. But it is COM API), you really should give more information on what type of application you are to develop. From the very limited description of yours, by vaguely mentioned that you ran into "invalid application" error by using .NET API (? Do I guess it correctly), I suspect that you are doing a EXE app (or a DLL to be used in another EXE app or even in a service type app) with AutoCAD .NET API assemblies referenced. If so, that is the reason of the error: you cannot use AutoCAD .NET assemblies outside AutoCAD process. 

 

So, again, you need to provide more detailed description of what type of application you are to do.

 

Norman Yuan

Drive CAD With Code

EESignature

0 Likes
Message 4 of 8

Christopher.hartman
Enthusiast
Enthusiast

Thank you Norman - I appreciate your candor! And yes you are correct - I have no experience with AutoCAD or AutoCAD APIs.

 

What I am tasked to do is to take a process currently using AutoHotKey and make that work in a C# .NET desktop application or windows service or web API.  The AutoHotKey script basically opens an AutoCAD template, inserts drawings, deletes "tabs" that are not needed, and saves that template as a drawing on a network share.  I am being asked to make that process work without having to interact with AutoCAD.  I initially tried the AutoCAD .NET assemblies - and yes you are correct - I did receive the error message because I was attempting to use the assemblies outside AutoCAD.  So that's when I turned to the AutoCAD COM API route.  I have been able to open a DWT file and save it as a DWG file - but that's as far as I have gotten.  I can't seem to find examples or detailed documentation on how to use the COM API.

 

Here is a snippet of what I have so far:

 

using AutoCAD;

 

private void OpenTemplate()
{
// Getting running AutoCAD instance by Marshalling by passing Programmatic ID as a string, AutoCAD.Application is the Programmatic ID for AutoCAD.
try
{
AcadApp = (AcadApplication)Marshal.GetActiveObject("AutoCAD.Application");
}
catch (Exception)
{
return;
}

AcadApp.Documents.Open(@"C:\Templates\TEST_BASE.dwt");
AcadDoc = AcadApp.ActiveDocument;
AcadDB = AcadDoc.Database;
AcadDoc.SaveAs(@"TEST_FINAL.dwg", AcSaveAsType.ac2018_dwg);
}

 

Do you have any suggestions on how I can accomplished what I am tasked to do? Resources/References?

 

Thanks

0 Likes
Message 5 of 8

_gile
Consultant
Consultant
Accepted solution

Hi,

You should have a look at the ActiveX: Reference Guide.



Gilles Chanteau
Programmation AutoCAD LISP/.NET
GileCAD
GitHub

0 Likes
Message 6 of 8

Christopher.hartman
Enthusiast
Enthusiast

Yes - that is what I was looking for!  Thank you!

0 Likes
Message 7 of 8

norman.yuan
Mentor
Mentor
Accepted solution

Well, doing things in AutoCAD with COM API (via .NET interop, in your case)  as you asked (removing undesired layout, or tab, as you stated, from external app (AutoHotKey) is relatively easy.

 

However, you need to realize, the solution you are developing is only good when it runs as desktop app, as if the AutoHotKey is a human CAD user controlling AutoCAD running session. Since you mentioned windows services/web API, I guess you eventually want to run the solution as unattended server app, which is big NO: you should not run full desktop AutoCAD app as service app, for tons of reasons.

 

Therefore, while learning AutoCAD COM API may be beneficial for you, but using it to automate AutoCAD on service/server side would not applicable. You would look into using AutoCAD's core console, or better yet, Autodesk's forge services, which would drive you to learn AutoCAD .NET API.

 

Since you are still green on both AutoCAD .NET API and COM API, you'd better choose one that leads to build a viable solution you are asked to do.

 

Norman Yuan

Drive CAD With Code

EESignature

Message 8 of 8

Christopher.hartman
Enthusiast
Enthusiast

Can Core Console be run on an IIS server? And there an advantage of Core Console over Forge's Automation API?

0 Likes