A .NET Framework project demonstrating how to expose AutoCAD document events through COM interop and consume them from an external console application.
This solution consists of two projects:
- InteropFromAcadAddin - AutoCAD add-in that exposes document events via COM
- AcadDocEventsTester - Console application that subscribes to and displays AutoCAD events in real-time
- 24 Real-time AutoCAD Events monitored:
- Document Command Events (Start, End, Cancel, Fail, Unknown)
- LISP Events (Start, End, Cancel)
- Document Close Events
- DocumentManager Events (Created, Activated, Destroyed, Lock Mode changes, etc.)
- Color-coded console output with timestamps
- COM connection point architecture bypassing ServicedComponent transparent proxy issues
- Visual Studio 2022
- AutoCAD 2024 (or adjust version in code)
- .NET Framework 4.8
- AutoCAD .NET API references
# Open the solution in Visual Studio
# Build in Debug or Release mode (x64)
# Solution will output to:
# - InteropFromAcadAddin: bin\x64\Debug\InteropFromAcadAddin.dll
# - AcadDocEventsTester: bin\Debug\AcadDocEventsTester.exeOpen Command Prompt as Administrator and navigate to your AutoCAD 2024 installation directory:
cd "C:\Program Files\Autodesk\AutoCAD 2024"
regasm "<YouPath>\InteropFromAcadAddin\InteropFromAcadAddin\bin\x64\Debug\InteropFromAcadAddin.dll" /codebase /tlbNote: Adjust paths according to your AutoCAD installation and project location.
In the AcadDocEventsTester project:
- Right-click References → Add Reference
- Click Browse and navigate to:
<YouPath>\InteropFromAcadAddin\InteropFromAcadAddin\bin\x64\Debug\InteropFromAcadAddin.dll - Click OK
This provides IntelliSense for the IDocumentEventService and IDocumentEventServiceEvents interfaces.
- Launch AutoCAD 2024
- Type
NETLOADat the command prompt - Browse to and select:
<YouPath>\InteropFromAcadAddin\InteropFromAcadAddin\bin\x64\Debug\InteropFromAcadAddin.dll - The add-in will register itself and start monitoring
- Run AcadDocEventsTester.exe (from Visual Studio or directly)
- The console will connect to the running AutoCAD instance
- You should see:
**AutoCAD Event Monitor** Connected to: AutoCAD 24.3 Plugin service retrieved successfully. Service started - now monitoring AutoCAD events. Event subscription successful! --- Listening for AutoCAD events --- Run commands in AutoCAD to see events here. Press ENTER to stop monitoring...
- Execute commands in AutoCAD (LINE, CIRCLE, MOVE, etc.)
- Open/close documents
- Switch between documents
- All events will appear in the console with color-coding and timestamps
Example Output:
[14:23:45.123] CMD START: 'LINE' | Drawing1.dwg
[14:23:47.456] CMD END: 'LINE' | Drawing1.dwg
[14:23:50.789] DOC CREATED | Drawing2.dwg
[14:23:51.012] DOC BECAME CURRENT | Drawing2.dwg
- Press ENTER in the console application to disconnect and exit
- The AutoCAD add-in continues running until AutoCAD closes
InteropFromAcadAddin/
├── InteropFromAcadAddin/ # AutoCAD Add-in Project
│ ├── PluginEntry.cs # Main COM server + event implementation
│ ├── Properties/AssemblyInfo.cs # COM visibility settings
│ └── scripts/
│ ├── Register-AcadAddin.bat # RegAsm registration helper
│ └── Unregister-AcadAddin.bat
│
└── AcadDocEventsTester/ # Console Client Project
├── Program.cs # COM connection + vtable interop
└── ComEventSink.cs # Event sink implementation
This implementation currently monitors Document and DocumentManager events. You can extend it to include:
- Database Events (ObjectAppended, ObjectModified, ObjectErased, etc.)
- Editor Events (PromptForSelection, etc.)
- Layout Manager Events
- Plot Events
- Application Events
Reference Sample: Check out the comprehensive EventsWatcher sample in the AutoCAD SDK:
<YouPath>\ARX2026\samples\dotNet\EventsWatcher
- Ensure the DLL is registered with RegAsm (with
/codebaseflag) - Verify the DLL is NETLOAD'ed in AutoCAD
- This project uses direct vtable calls to bypass ServicedComponent proxy issues
- Ensure you're using the updated
Program.cswithFindConnectionPoint,Advise,Unadvisemethods
- Always run
regasmas Administrator - Use the
/codebaseflag to register the DLL location - Verify bitness matches (x64 AutoCAD requires x64 DLL)
-
COM Interface GUIDs:
IDocumentEventService:D1C762E4-2C22-482B-9333-82F3E906E6B4IDocumentEventServiceEvents:A7E1B0A4-2E2E-4B6D-9E39-7D6C5B2C9A11PluginEntryCLSID:75B37C6C-8047-41E3-8C4D-D5196EEFF368
-
Architecture:
- Uses COM connection points for event marshaling
- Direct vtable calls to bypass .NET Remoting transparent proxies
- ServicedComponent base class for COM+ compatibility with AutoCAD
This is a demonstration project for educational purposes.
Watch the demonstration video showing the event monitor in action:
Demo.mp4
Or download: Demo.mp4
The video demonstrates:
- Loading the AutoCAD add-in with NETLOAD
- Running the console application
- Real-time event monitoring as commands are executed
- Color-coded event output with timestamps
- Document lifecycle events (create, activate, close)
Note: Paths in this README are examples. Adjust them to match your actual project location and AutoCAD installation directory.