solidworks_mcp.agents.soc_exporter¶
solidworks_mcp.agents.soc_exporter ¶
SolidWorks-as-Code exporter.
Reads ToolCallRecord rows from SQLite for a session and emits a clean, runnable Python script that mirrors the structure of build_u_bracket_artifact.py.
Usage::
from solidworks_mcp.agents.soc_exporter import export_session
export_session("my-session-id", output_path="my_part.py")
CLI::
python -m solidworks_mcp.agents.soc_exporter <session_id> <output_path>
Attributes¶
_SCRIPT_FOOTER
module-attribute
¶
_SCRIPT_FOOTER = ' finally:\n await adapter.disconnect()\n\n\nif __name__ == "__main__":\n asyncio.run(build_part())\n'
_SCRIPT_HEADER
module-attribute
¶
_SCRIPT_HEADER = 'from __future__ import annotations\n\nimport asyncio\nfrom pathlib import Path\nfrom typing import Any\n\nfrom solidworks_mcp.adapters import create_adapter\nfrom solidworks_mcp.adapters.base import ExtrusionParameters\nfrom solidworks_mcp.config import load_config\n\n\ndef require(result: Any, label: str) -> Any:\n if not result.is_success:\n raise RuntimeError(f"{label} failed: {result.error}")\n return result\n\n\nasync def build_part() -> None:\n config = load_config()\n adapter = await create_adapter(config)\n await adapter.connect()\n try:\n'
Classes¶
_CodeGen ¶
Stateful generator that tracks entity variables across one sketch.
Source code in src/solidworks_mcp/agents/soc_exporter.py
Methods:¶
emit_generic ¶
Emit adapter.
This gives every logged tool call valid, runnable Python code even if the exporter has no specialized emitter for it. The adapter method name and its keyword-argument names come directly from the logged input_json, so they match the actual adapter API.
Source code in src/solidworks_mcp/agents/soc_exporter.py
Functions:¶
_checkpoint_comment ¶
Render a SoCCheckpoint as a parseable comment block.
Source code in src/solidworks_mcp/agents/soc_exporter.py
_cli ¶
Source code in src/solidworks_mcp/agents/soc_exporter.py
_coord ¶
Return the first non-None value from inp for the given keys as a float.
Source code in src/solidworks_mcp/agents/soc_exporter.py
_entity_id_from_output ¶
Extract entity_id from an AdapterResult output dict.
Source code in src/solidworks_mcp/agents/soc_exporter.py
_fmt_num ¶
_parse_input ¶
Source code in src/solidworks_mcp/agents/soc_exporter.py
_parse_output ¶
Source code in src/solidworks_mcp/agents/soc_exporter.py
_r ¶
export_session ¶
export_session(session_id: str, output_path: str | Path, *, checkpoint_id: int | None = None, db_path: Path | None = None, skip_failed: bool = True) -> Path
Export a session's ToolCallRecords as a runnable Python script.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
session_id
|
str
|
The session ID to export. |
required |
output_path
|
str | Path
|
Destination .py file path. |
required |
checkpoint_id
|
int | None
|
If set, export only records from this checkpoint. |
None
|
db_path
|
Path | None
|
Override default SQLite DB path. |
None
|
skip_failed
|
bool
|
Skip failed tool call records (default True). |
True
|
Returns:
| Type | Description |
|---|---|
Path
|
Path to the written file. |
Source code in src/solidworks_mcp/agents/soc_exporter.py
generate_script ¶
generate_script(records: list[dict[str, Any]], *, session_id: str | None = None, checkpoints: list[dict[str, Any]] | None = None, skip_failed: bool = True) -> str
Generate a Python script from a list of ToolCallRecord dicts.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
records
|
list[dict[str, Any]]
|
Ordered list of ToolCallRecord dicts (from list_tool_call_records). |
required |
session_id
|
str | None
|
Optional session ID to embed in header comment. |
None
|
checkpoints
|
list[dict[str, Any]] | None
|
Optional list of SoCCheckpoint dicts (from list_soc_checkpoints). When provided, checkpoint comment blocks are inserted between the corresponding record boundaries. |
None
|
skip_failed
|
bool
|
Skip records where success=False (default True). |
True
|
Returns:
| Type | Description |
|---|---|
str
|
Complete Python script as a string. |
Source code in src/solidworks_mcp/agents/soc_exporter.py
list_tool_call_records ¶
list_tool_call_records(session_id: str, checkpoint_id: int | None = None, db_path: Path | None = None, include_reverted: bool = False) -> list[dict[str, Any]]
List tool call records for a session and optional checkpoint.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
session_id
|
str
|
The session id value. |
required |
checkpoint_id
|
int | None
|
The checkpoint id value. Defaults to None. |
None
|
db_path
|
Path | None
|
The db path value. Defaults to None. |
None
|
include_reverted
|
bool
|
Include records with status='reverted'. Defaults to False. |
False
|
Returns:
| Type | Description |
|---|---|
list[dict[str, Any]]
|
list[dict[str, Any]]: A list containing the resulting items. |