This guide demonstrates how to expose COM server components in .NET Core and utilize them in AutoCAD using GetInterfaceObject. This workflow is suitable for AutoCAD 2025 and later versions.
COM (Component Object Model) provides a standardized way for software components to communicate and has been a popular technology for extending AutoCAD for many years. While .NET Framework had seamless support for COM, achieving this in .NET Core or .NET 5+ requires additional effort but enables the use of modern frameworks like .NET 8.0.
In this example, we’ll create a COM server to calculate Pi and use it in AutoCAD.
Both .NET 8 and ARX add-in projects are provided.
We will register the COM server created in .NET 8.0 and consume it in both .NET Core and ARX AutoCAD plugins.
To consume the server, we will use the GetInterfaceObject AutoCAD ActiveX API.
graph TB
subgraph Contracts
C1["Contract.idl
(for C++ clients)"]
C2["COMServer.Contracts.dll
(for .NET clients)"]
end
subgraph Server
S["COMServer
(.NET 8 comhost)"]
end
subgraph Clients
N["C++ ARX Addin"]
M[".NET AcadNetAddin"]
end
C1 -->|"MIDL / TLB"| N
C2 -->|"ProjectReference"| M
S -->|"Implements Interface"| C2
N -->|"AutoCAD.GetInterfaceObject()"| S
M -->|"AutoCAD.GetInterfaceObject()"| S
IServer (COM interface)
(shared: COMServer.Contracts)
|
Implements
|
COMServer (.NET comhost)
(registered, exposes Class)
/ \
GetInterfaceObject() GetInterfaceObject()
(Acad .NET) (C++ / ARX)
(ProjectRef -> Contracts) (Contract.idl / Contract_i.h)
Ensure the following tools and environments are set up before proceeding:
- AutoCAD 2025 or later
- Visual Studio 2022 (v17.10 or later)
- .NET 8.0 SDK
Follow these steps to clone, build, and run the example:
-
Clone the repository:
git clone https://github.com/MadhukarMoogala/AcadCOMServer.git cd AcadCOMServer -
Restore dependencies and build the project:
cd ComServer dotnet restore dotnet build -
Register the COM server:
regsvr32 ~AcadCOMServer\Binaries\net8.0\COMServer.comhost.dll
-
Build the AutoCAD .NET plugin
cd AcadNetAddin dotnet build -
Build the AutoCAD Arx plugin
cd AcadArxAddin msbuild /t:build /p:Configuration=Debug;Platform=x64
-
Launch AutoCAD 2025 and load the plugin:
-
Use the
NETLOADcommand to load the .NET app.~AcadComServer\Binaries\net8.0\AcadNetAddin.dll -
Use the
Apploadcommand to load the arx app.~AcadComServer\Binaries\net8.0\AcadArxAddin.dll
-
-
Run the
RunDotnetcommand:- A calculated value of Pi will be written to the AutoCAD command line.
-
Run the
RunArxcommand :- A calculated value of Pi will be written to the AutoCAD command line.
To get started with the repository and build the solution, follow these steps:
-
Launch Visual Studio with Administrative Privileges
- Ensure Visual Studio is run as an administrator to handle any system-level dependencies during the build process.
-
Clone the Repository
- On the Visual Studio start page, select Clone a Repository.
- Enter the following GitHub URL in the repository location field:
https://github.com/MadhukarMoogala/AcadCOMServer.git - Choose the desired folder path where you want to clone the repository, and click Clone.
-
Set Up the ObjectARX SDK Path
- After the cloning process, navigate to the
AcadArxAddinproject within the solution. - Right-click on the
AcadArxAddinproject in Solution Explorer, select Properties, and set the path to your installed ObjectARX SDK.- For example, update the Include Directories and Library Directories paths in the project settings.
- Ensure that the ObjectARX SDK is correctly installed and accessible.
- After the cloning process, navigate to the
-
Restore NuGet Packages
- Visual Studio will automatically detect and restore any missing NuGet packages upon opening the solution. If needed, you can manually restore packages by right-clicking the solution in Solution Explorer and selecting Restore NuGet Packages.
-
Build the Solution
- Right-click on the solution in Solution Explorer and select Build Solution.
- Verify that all projects build successfully without errors.
-
Run and Test
-
Once the build is complete, the
COM Server, theAcadArxAddinand theAcadNetAddinwill be ready to use. -
Don't forget
regsiter the COM Server -
Launch AutoCAD 2025 and load the plugin:
-
Use the
NETLOADcommand to load the .NET app.~AcadComServer\Binaries\net8.0\AcadNetAddin.dll -
Use the
Apploadcommand to load the arx app.~AcadComServer\Binaries\net8.0\AcadArxAddin.dll
-
-
Run the
RunDotnetcommand:- A calculated value of Pi will be written to the AutoCAD command line.
-
Run the
RunArxcommand :- A calculated value of Pi will be written to the AutoCAD command line.
-
Madhukar Moogala APS Developer Advocate