Call a .NET module from out-of-process ActiveX VBA?

Call a .NET module from out-of-process ActiveX VBA?

michellem
Advocate Advocate
225 Views
1 Reply
Message 1 of 2

Call a .NET module from out-of-process ActiveX VBA?

michellem
Advocate
Advocate

Hello;

I have been working on a program on and off for about a year using ActiveX to access a dwg file but I keep bumping into the limitations of AutoCAD's VBA api. Specifically, there are entity properties exposed in .NET that are not exposed in the ActiveX API. For example, if you have a rotated dimension, you can not access the start points of the extension lines with ActiveX but you can with .NET.

 

The program I am working on must run in the process space of Revit but I need to access the dwg file in the process space of Autocad. As Kean Walmsley of Through The Interface once said:

"COM’s big advantage – and frankly the main reason I use it at all – is that it was designed to be used across processes. While .NET Remoting is possible with some applications, AutoCAD’s managed interface was not designed to work across the process boundary (just as ObjectARX was not)."

 

So the solution seems to be to create a .NET dll that is a COM server. A daunting task. As outlined 15 years ago here:
Interfacing-an-external-com-application-with-a-net-module-in-process-to-autocad-redux (Through The I... 

 

So I was wondering if anyone knew of a sample source code or a framework that I could easily insert some functions to expose the properties I need? And only those properties - no need to recreate the whole car; just the parts that are missing.

 

Or perhaps someone might know of more recent info about how to create a COM server for Autocad?

 

I am using Autocad 2023 and Revit 2020 and up. Program should also run on some earlier and later versions of AutoCad.

 

Sincerely;

Michelle

 

 

 

 

0 Likes
226 Views
1 Reply
Reply (1)
Message 2 of 2

norman.yuan
Mentor
Mentor

Exposing AutoCAD .NET API components as COM has been the same up to Acad2024 with .NET Framework. With AutoCAD 2025, since it uses .NET 8, the exposing .NET stuff as COM becomes more complicated. I did it with pre-Acad2025, but not with Acad2025. A recent discussion in this forum here indicates there could be difficulties and the OP's question remains unanswered:

https://forums.autodesk.com/t5/net/accessing-com-components-using-the-acadapplication/td-p/13074044 

 

Personally, I would not waste time to go this route because of its technical difficulty and tediousness (having to register the COM components every time the code updated).

 

Depending on how the code execution in your main app (Revit) needs to communicate a running AutoCAD, or the drawing data is needed, there could be different pure .NET solution. I would try to let the Revit collect drawing data once per drawing at some point of the execution as async call to external data source (in this case, it is a running AUtoCAD session). the call can use COM's SendCommand to run a .NET plugin command, which would collect all required data. Then the data can be saved as temp data file (json/Xml...) and signal the end to the Revit calling process. In this case, it would better to use Acad core console instead of AutoCAD desktop. Or, maybe, simply use Autodesk's APS Design Automation cloud service, so no local AutoCAD installation is required for users (you still need a locally installed Auto CAD to develop your AutoCAD .NET components).

 

 

Norman Yuan

Drive CAD With Code

EESignature

0 Likes