solidworks_mcp.adapters.solidworks.drawing_pack¶
solidworks_mcp.adapters.solidworks.drawing_pack ¶
The drawing pack (queue item 12): section and detail views, title block and
sheet format edits, drawing dimensions, and the facts check_drawing reads.
Every position is in sheet millimetres, as in the other drawing tools. COM calls (argument lists from the installed type library):
IDrawingDoc.ActivateView(Name);ISketchManager.CreateLineandCreateCircleByRadiusin the active view's sketch;IDrawingDoc.CreateSectionViewAt5(X, Y, Z, SectionLabel, Options, ExcludedComponents, SectionDepth)andCreateDetailViewAt4(X, Y, Z, Style, Scale1, Scale2, LabelIn, Showtype, FullOutline, JaggedOutline, NoOutline, ShapeIntensity)on the selected line or circle;IModelDoc2.AddHorizontalDimension2/AddVerticalDimension2/AddDimension2/AddRadialDimension2/AddDiameterDimension2after picking edges by sheet point (SelectByID2with the null callout);IDrawingDoc.AutoDimension(Entities, HScheme, HPlacement, VScheme, VPlacement)on the active view;IDrawingDoc.SetupSheet5for a new format and paper size (the callgenerate_drawing_packagealready makes);IView.GetSketch().ModelToSketchTransform(sheet to view sketch space);IView.GetOutline,GetDisplayDimensionCount,IAnnotation.IsDanglingfor the drawing report.
Enum values were read from swconst.tlb (SolidWorks 2026).
Attributes¶
PAPER_SIZES
module-attribute
¶
PAPER_SIZES: dict[str, tuple[int, float, float]] = {'a4': (6, 297.0, 210.0), 'a3': (8, 420.0, 297.0), 'a2': (9, 594.0, 420.0), 'a1': (10, 841.0, 594.0), 'a0': (11, 1189.0, 841.0)}
TITLE_BLOCK_FIELDS
module-attribute
¶
TITLE_BLOCK_FIELDS: dict[str, tuple[str, str]] = {'title': ('model', 'Description'), 'drawing_number': ('drawing', 'DrawingNo'), 'drawn_by': ('drawing', 'DrawnBy'), 'drawn_date': ('drawing', 'DrawnDate'), 'revision': ('drawing', 'Revision'), 'company': ('drawing', 'COMPANYNAME')}
VIEW_TYPES
module-attribute
¶
VIEW_TYPES = {1: 'sheet', 2: 'section', 3: 'detail', 4: 'projected', 5: 'auxiliary', 6: 'standard', 7: 'named', 8: 'relative', 9: 'detached', 10: 'alternate position'}
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. |
InputRefused ¶
Bases: ValueError
The adapter checked an input against the document and refused it.
An expected answer, not a fault: a section line that misses its view, a
point with nothing to dimension. It is logged as one line, without a
traceback, and the tools classify it as invalid_input.
SolidWorksDrawingPackMixin ¶
Section and detail views, title block and format, dimensions, report.
Methods:¶
add_dimension
async
¶
add_dimension(dimension_type: str, entity1_point: list[float], position: list[float], entity2_point: list[float] | None = None) -> AdapterResult[dict[str, Any]]
One dimension on the entities picked at sheet points.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
dimension_type
|
str
|
horizontal, vertical, aligned, radial, diameter or angular. |
required |
entity1_point
|
list[float]
|
|
required |
position
|
list[float]
|
|
required |
entity2_point
|
list[float] | None
|
The second entity, for linear and angular types. |
None
|
Returns:
| Type | Description |
|---|---|
AdapterResult[dict[str, Any]]
|
The dimension's name and value (mm, degrees for angular). |
Source code in src/solidworks_mcp/adapters/solidworks/drawing_pack.py
auto_dimension_view
async
¶
SolidWorks' auto-dimension on one view, counted before and after.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
view
|
str
|
The view's name. |
required |
scheme
|
str
|
|
'baseline'
|
Returns:
| Type | Description |
|---|---|
AdapterResult[dict[str, Any]]
|
The view, the scheme, and the dimensions before, after and added. |
Source code in src/solidworks_mcp/adapters/solidworks/drawing_pack.py
create_detail_view
async
¶
create_detail_view(view: str, center: list[float], radius: float, position: list[float], scale: str = '2:1', label: str | None = None) -> AdapterResult[dict[str, Any]]
A detail view of the circle at center in view.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
view
|
str
|
The parent view's name. |
required |
center
|
list[float]
|
|
required |
radius
|
float
|
The circle's radius on the sheet, mm. |
required |
position
|
list[float]
|
|
required |
scale
|
str
|
The detail's scale, e.g. |
'2:1'
|
label
|
str | None
|
The detail's letter; the next free one when |
None
|
Returns:
| Type | Description |
|---|---|
AdapterResult[dict[str, Any]]
|
The new view's name, label, scale and outline. |
Source code in src/solidworks_mcp/adapters/solidworks/drawing_pack.py
create_section_view
async
¶
create_section_view(view: str, line_start: list[float], line_end: list[float], position: list[float], label: str | None = None) -> AdapterResult[dict[str, Any]]
A section view cut along a line across view.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
view
|
str
|
The parent view's name. |
required |
line_start
|
list[float]
|
|
required |
line_end
|
list[float]
|
|
required |
position
|
list[float]
|
|
required |
label
|
str | None
|
The section's letter; the next free one when |
None
|
Returns:
| Type | Description |
|---|---|
AdapterResult[dict[str, Any]]
|
The new view's name, label and outline. |
Source code in src/solidworks_mcp/adapters/solidworks/drawing_pack.py
drawing_report
async
¶
What check_drawing judges: views, sheet, title block, BOM, dangling.
Returns:
| Type | Description |
|---|---|
AdapterResult[dict[str, Any]]
|
|
AdapterResult[dict[str, Any]]
|
|
AdapterResult[dict[str, Any]]
|
|
Source code in src/solidworks_mcp/adapters/solidworks/drawing_pack.py
update_sheet_format
async
¶
update_sheet_format(sheet_format: str, paper_size: str | None = None) -> AdapterResult[dict[str, Any]]
Change the active sheet's format and paper size, keeping its views.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
sheet_format
|
str
|
A format name ( |
required |
paper_size
|
str | None
|
a4 to a0; read from the format name when |
None
|
Returns:
| Type | Description |
|---|---|
AdapterResult[dict[str, Any]]
|
The format's path, the paper size and the views before and after. |
Source code in src/solidworks_mcp/adapters/solidworks/drawing_pack.py
update_title_block
async
¶
Write title-block fields to the properties the sheet format reads.
title goes to the drawn model's Description (the ISO format reads
it with $PRPSHEET); the rest are the drawing's own properties.
Fields not given keep their values.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
fields
|
dict[str, str]
|
Field name (a key of :data: |
required |
Returns:
| Type | Description |
|---|---|
AdapterResult[dict[str, Any]]
|
Each field with the property it was written to. |
Source code in src/solidworks_mcp/adapters/solidworks/drawing_pack.py
Functions:¶
_as_com ¶
Wrap a raw dispatch and flag its methods for an interface.
Objects handed back inside arrays (GetViews and friends) arrive as raw
PyIDispatch. Method flagging is a no-op on those, so every call
against them raises until they are wrapped through dynamic.Dispatch.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
adapter
|
Any
|
A connected |
required |
obj
|
Any
|
The raw dispatch. |
required |
interface
|
str
|
Interface name, e.g. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
Any |
Any
|
The wrapped, flagged object, or |
Source code in src/solidworks_mcp/adapters/solidworks/io.py
_mm ¶
A COM outline in metres -> mm, or None when unreadable.
Source code in src/solidworks_mcp/adapters/solidworks/drawing_pack.py
_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
_read_custom_property ¶
Read one custom property's (value, resolved value).
Tries Get6 (value and resolved value) first; under late binding on
SW 2025 its out-parameters raise Parameter not optional, so it falls
back to Get(name), which returns the stored text only.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
adapter
|
Any
|
The adapter, for its |
required |
manager
|
Any
|
The document's |
required |
name
|
str
|
Property name. |
required |
Returns:
| Type | Description |
|---|---|
str
|
tuple[str, str]: The stored value and the resolved value; empty |
str
|
strings when the property cannot be read. |
Source code in src/solidworks_mcp/adapters/solidworks/documentation.py
_resolve_drawing_view ¶
Return the IView on the active drawing whose name matches.
Walks IDrawingDoc::GetViews (a list of sheets, each shaped
(sheet, view, view, ...)) the same way :func:_view_names does. The
match is case-insensitive.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
adapter
|
Any
|
A connected |
required |
drawing
|
Any
|
The drawing document, flagged for |
required |
view_name
|
str
|
The drawing-view name to look for. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
Any |
Any
|
The flagged |
Source code in src/solidworks_mcp/adapters/solidworks/io.py
_to_sketch ¶
A model point (metres) in sketch's coordinates.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
adapter
|
Any
|
The connected adapter (its |
required |
sketch
|
Any
|
An |
required |
point_m
|
list[float]
|
|
required |
Returns:
| Type | Description |
|---|---|
list[float]
|
|
Source code in src/solidworks_mcp/adapters/solidworks/part_features.py
_view_names ¶
Return the drawing's view names, excluding sheet formats.
CreateDrawViewFromModelView3 returns None for a model SolidWorks
could not resolve, and Create3rdAngleViews2 returns a bare boolean, so
the view list is the ground truth for whether views were really added.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
adapter
|
Any
|
A connected |
required |
drawing
|
Any
|
The drawing document, flagged for |
required |
Returns:
| Type | Description |
|---|---|
list[str]
|
list[str]: View names in sheet order. |
Source code in src/solidworks_mcp/adapters/solidworks/io.py
as_list ¶
Normalise a COM array/scalar/None return into a list.
double_array ¶
VARIANT(VT_ARRAY | VT_R8) for array-valued COM properties (tuple when pywin32 is absent).
Source code in src/solidworks_mcp/adapters/solidworks/com_utils.py
find_sheet_format ¶
Locate a sheet format file: SolidWorks' configured folder, then ProgramData.
Source code in src/solidworks_mcp/adapters/solidworks/drawing_standard.py
inside ¶
Whether point lies in box (edges included).
next_label ¶
The first letter no section or detail view uses yet ("A" when none).
Source code in src/solidworks_mcp/adapters/solidworks/drawing_pack.py
paper_for ¶
The paper size: given, else the format name's (a2 - iso -> a2).
Raises:
| Type | Description |
|---|---|
ValueError
|
When neither names one of :data: |
Source code in src/solidworks_mcp/adapters/solidworks/drawing_pack.py
parse_scale ¶
"3:1" -> (3.0, 1.0).
Raises:
| Type | Description |
|---|---|
ValueError
|
For anything but two positive numbers around a colon. |
Source code in src/solidworks_mcp/adapters/solidworks/drawing_pack.py
segment_crosses_box ¶
Whether the segment from start to end touches the box (Liang-Barsky).