solidworks_mcp.adapters.solidworks.dialog_watch¶
solidworks_mcp.adapters.solidworks.dialog_watch ¶
Answer a dialog a running macro left waiting for the user (issue #97).
RunMacro2 doesn't return while a macro waits on a dialog (a MsgBox, a
user form, a SolidWorks prompt), and COM calls can't move off the connect
thread to time it out. :class:DialogWatch runs beside the call on its own
thread and uses only Win32 window calls, never COM. When a dialog the
SolidWorks process opened stays up longer than the timeout, it reads the
dialog and answers it with the non-committal choice:
- Cancel, when the dialog has that button;
- else its only button, when it has just one (an OK acknowledgement);
- else, with no buttons (a VBA user form), it closes the window.
A dialog with several buttons and no Cancel (Yes/No) is left for the user and logged: pressing Yes or No could change the model.
Attributes¶
Classes¶
DialogSeen
dataclass
¶
A dialog the watch found waiting, and what it did.
Attributes:
| Name | Type | Description |
|---|---|---|
title |
str
|
The dialog's title. |
text |
str
|
Its message, the static texts joined. |
buttons |
tuple[str, ...]
|
Its button labels, without |
answer |
str | None
|
|
Methods:¶
describe ¶
One line: the dialog, its text, and how it was answered.
Source code in src/solidworks_mcp/adapters/solidworks/dialog_watch.py
DialogWatch
dataclass
¶
DialogWatch(pid: int, timeout: float, windows: Windows = Win32Windows(), poll: float = 0.5, clock: Callable[[], float] = time.monotonic, seen: list[DialogSeen] = list())
Watch process pid for a dialog left waiting, while a call runs.
Use it as a context manager around the blocking call. Dialogs already open when it starts are ignored.
Attributes:
| Name | Type | Description |
|---|---|---|
pid |
int
|
The SolidWorks process ID. |
timeout |
float
|
Seconds a dialog may stay open before it is answered. |
windows |
Windows
|
The window calls; the real Win32 ones by default. |
poll |
float
|
Seconds between looks. |
clock |
Callable[[], float]
|
The time source, in seconds. |
seen |
list[DialogSeen]
|
Every dialog answered or left, in the order found. |
Methods:¶
__enter__ ¶
Note the dialogs already open and start watching.
Source code in src/solidworks_mcp/adapters/solidworks/dialog_watch.py
__exit__ ¶
__exit__(exc_type: type[BaseException] | None, exc: BaseException | None, tb: TracebackType | None) -> None
Stop watching.
Source code in src/solidworks_mcp/adapters/solidworks/dialog_watch.py
__post_init__ ¶
Set up the thread state.
Source code in src/solidworks_mcp/adapters/solidworks/dialog_watch.py
check ¶
Answer any new dialog that has been open longer than the timeout.
Source code in src/solidworks_mcp/adapters/solidworks/dialog_watch.py
Win32Windows ¶
:class:Windows over win32gui and win32process.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
gui
|
Any
|
The |
None
|
process
|
Any
|
The |
None
|
Keep the two modules.
Source code in src/solidworks_mcp/adapters/solidworks/dialog_watch.py
Methods:¶
children ¶
A window's children as (hwnd, class name, text).
Source code in src/solidworks_mcp/adapters/solidworks/dialog_watch.py
control_id ¶
dialogs ¶
Visible top-level dialog windows of process pid.
Source code in src/solidworks_mcp/adapters/solidworks/dialog_watch.py
post ¶
Post a message to a window without waiting for it.
Windows ¶
Functions:¶
waited_message ¶
The error for a macro that waited on dialogs.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
seen
|
list[DialogSeen]
|
The dialogs the watch found. |
required |
timeout
|
float
|
The timeout that was used, in seconds. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
str |
str
|
What happened, and that macros here must not wait for the user. |