Skip to content

Connection Mixin

Handles COM connection lifecycle: connect, disconnect, reconnect, and application detection.

adapters.mixins.connection_mixin.ConnectionMixin

Mixin for connection management.

connect

connect(only_if_running: bool = False) -> bool

Connect to the CAD application via COM, initializing COM for this thread.

Tries to attach to an already-running instance first. If none is found and only_if_running is False, launches a new instance.

PARAMETER DESCRIPTION
only_if_running

When True, return False instead of launching a new CAD instance if none is currently running.

TYPE: bool DEFAULT: False

RETURNS DESCRIPTION
bool

True if the connection was established successfully.

RAISES DESCRIPTION
CADConnectionError

If COM initialization fails or the ProgID is invalid.

disconnect

disconnect() -> bool

Disconnect from CAD application with COM cleanup.

is_connected

is_connected() -> bool

Check if connected to CAD application.

check_document_change

check_document_change() -> bool

Check if the active document in the CAD application has changed. If it has, update self.document to the new active document.

RETURNS DESCRIPTION
bool

True if the document changed, False otherwise.

TYPE: bool