AutoCAD Adapter¶
The main adapter class composed from 11 specialized mixins. Supports AutoCAD, ZWCAD, GstarCAD, and BricsCAD via the same interface.
adapters.autocad_adapter
¶
AutoCAD adapter for multiCAD-MCP.
Implements CADInterface for AutoCAD using Windows COM. Supports AutoCAD, ZWCAD, GstarCAD, and BricsCAD via factory pattern.
Refactored to use mixin classes for better organization and maintainability.
SelectionSetManager
¶
Context manager for safe SelectionSet handling.
Ensures SelectionSet cleanup even on exceptions, preventing orphaned selection sets that can cause issues in AutoCAD.
Example
with SelectionSetManager(document, "TEMP_SS") as ss: ss.Select(...) # ... use ss ...
Auto-deleted on exit¶
__init__
¶
Initialize SelectionSet manager.
| PARAMETER | DESCRIPTION |
|---|---|
document
|
AutoCAD document object
TYPE:
|
name
|
Name for the selection set
TYPE:
|
__enter__
¶
Create SelectionSet, deleting existing one if present.
| RETURNS | DESCRIPTION |
|---|---|
Any
|
Created SelectionSet object |
__exit__
¶
Cleanup SelectionSet on exit.
| PARAMETER | DESCRIPTION |
|---|---|
_exc_type
|
Exception type if raised
TYPE:
|
_exc_val
|
Exception value if raised
TYPE:
|
_exc_tb
|
Exception traceback if raised
TYPE:
|
AutoCADAdapter
¶
Bases: UtilityMixin, ConnectionMixin, DrawingMixin, LayerMixin, FileMixin, ViewMixin, SelectionMixin, EntityMixin, ManipulationMixin, BlockMixin, ExportMixin, CADInterface
Adapter for controlling AutoCAD via COM interface.
[... docstring truncated for brevity ...]
__init__
¶
Initialize AutoCAD adapter.
| PARAMETER | DESCRIPTION |
|---|---|
cad_type
|
Type of CAD (autocad, zwcad, gcad, bricscad)
TYPE:
|
com_session
¶
Context manager for safe COM initialization and cleanup.
Ensures CoInitialize/CoUninitialize are always paired, even on exceptions. Use this for all COM operations to prevent thread state leaks.
Example
with com_session(): app = win32com.client.Dispatch("AutoCAD.Application") # ... use app ...
com_safe
¶
Decorator for COM operation error handling.
Wraps method with: - Exception catching (pywintypes.com_error) - Operation logging - Automatic error conversion to CADOperationError
| PARAMETER | DESCRIPTION |
|---|---|
return_type
|
Expected return type (for type hints)
TYPE:
|
operation_name
|
Name of operation (for logging)
TYPE:
|