solidworks_mcp.adapters.solidworks.templates¶
solidworks_mcp.adapters.solidworks.templates ¶
Save the active document as a template (queue item 21).
IModelDocExtension.SaveAs writes a .prtdot, .asmdot or
.drwdot. SolidWorks then has the template open in place of the
document, as File > Save As does: seen live on SolidWorks 2026 for a part
never saved and for a saved one, and swSaveAsOptions_Copy doesn't
change it. The template folders are SolidWorks'
swFileLocationsDocumentTemplates preference, the folders File > New
shows.
Attributes¶
DOCUMENT_TYPES
module-attribute
¶
TEMPLATE_EXTENSIONS
module-attribute
¶
Classes¶
AdapterResult
dataclass
¶
AdapterResult(status: AdapterResultStatus, data: T | None = None, error: str | None = None, execution_time: float | None = None, metadata: dict[str, Any] | None = None)
Result wrapper for adapter operations.
Attributes:
| Name | Type | Description |
|---|---|---|
data |
T | None
|
The data value. |
error |
str | None
|
The error value. |
execution_time |
float | None
|
The execution time value. |
metadata |
dict[str, Any] | None
|
The metadata value. |
status |
AdapterResultStatus
|
The status value. |
AdapterResultStatus ¶
Bases: StrEnum
Result status for adapter operations.
Attributes:
| Name | Type | Description |
|---|---|---|
ERROR |
Any
|
The error value. |
SUCCESS |
Any
|
The success value. |
TIMEOUT |
Any
|
The timeout value. |
WARNING |
Any
|
The warning value. |
SolidWorksTemplatesMixin ¶
get_template_folders and save_as_template for the real adapter.
Methods:¶
get_template_folders
async
¶
The template folders, and the active document's template extension.
Returns:
| Type | Description |
|---|---|
AdapterResult[dict[str, Any]]
|
AdapterResult[dict[str, Any]]: |
AdapterResult[dict[str, Any]]
|
and |
Source code in src/solidworks_mcp/adapters/solidworks/templates.py
save_as_template
async
¶
Save the active document as a template at file_path.
SolidWorks then has the template open in place of the document (see the module docstring); the document's file, if it had one, is left as last saved. The title and path are read before and after, so the reply says what is open now.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
file_path
|
str
|
The template's full path, with the document's template extension. |
required |
Returns:
| Type | Description |
|---|---|
AdapterResult[dict[str, Any]]
|
AdapterResult[dict[str, Any]]: |
AdapterResult[dict[str, Any]]
|
|
AdapterResult[dict[str, Any]]
|
(the open document's path before the save, |
AdapterResult[dict[str, Any]]
|
saved) and |
Source code in src/solidworks_mcp/adapters/solidworks/templates.py
Functions:¶
_byref_int ¶
Return a byref long VARIANT for a SolidWorks out-parameter.
See :func:_byref_bstr for why pythoncom.Missing does not work.
Returns:
| Name | Type | Description |
|---|---|---|
Any |
Any
|
A |
Any
|
unavailable (test/mock environments). |
Source code in src/solidworks_mcp/adapters/solidworks/io.py
_doc_type ¶
Return the active document's type: 1 part, 2 assembly, 3 drawing.
GetType is one of the members pywin32 late binding may expose as either
a bound method or a plain value, so calling it directly returns None on
some documents. _get_attr_or_call handles both shapes.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
adapter
|
Any
|
A connected |
required |
Returns:
| Type | Description |
|---|---|
int | None
|
int | None: The document type, or |
Source code in src/solidworks_mcp/adapters/solidworks/io.py
_error ¶
_null_callout ¶
Return a VT_DISPATCH null for SelectByID2's Callout parameter.
A plain Python None marshals as VT_NULL, which SolidWorks rejects
with DISP_E_TYPEMISMATCH - measured as
(-2147352571, 'Type mismatch.', None, 8). See runbook item 11.
Returns:
| Name | Type | Description |
|---|---|---|
Any |
Any
|
A |
Any
|
when pywin32 is unavailable (mock/Linux runs, where no real COM call |
|
Any
|
will be made anyway, but the value must still never be bare |
Source code in src/solidworks_mcp/adapters/solidworks/features.py
in_folders ¶
Whether path sits directly in one of folders.
Compared as Windows paths (case and separators ignored), on any OS.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
path
|
str
|
A file path. |
required |
folders
|
list[str]
|
Folder paths. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
bool |
bool
|
True when the file's folder is one of them. |
Source code in src/solidworks_mcp/adapters/solidworks/templates.py
split_folders ¶
The folders in a ;-separated SolidWorks location preference.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
text
|
Any
|
The preference's value; anything not a string means none. |
required |
Returns:
| Type | Description |
|---|---|
list[str]
|
list[str]: The folders, in order, blanks dropped. |