Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,13 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

### Fixed

- **`create_drawing_view` keeps the sheet's scale.** SolidWorks's "Automatically
scale new drawing views" option rescaled an empty sheet to fit its first
view: a sheet set to 1:2 read 2:1 after a front view of a 30 mm block. The
scale is now set back (the option itself is left alone); the reply gives
`sheet_scale`, `sheet_rescale_undone` and `fits_sheet`, and the message
says when a view runs off the paper. `fit_sheet_scale: true` keeps
SolidWorks's fit. The live test passes on SolidWorks 2026.
- **A Bandit alert on the body tools.** The body operation's reply-fields
callback was named `extra`, which Bandit's rule B610 reads as Django's
`QuerySet.extra` (an SQL risk). There is no SQL; the callback is now
Expand Down
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -192,6 +192,7 @@ Each GIF is a live test driving SolidWorks 2026 through the MCP tools, with the
<tr>
<td width="33%" valign="top"><a href="https://andrewbartels1.com/SolidworksMCP-python/demos/#hole-positions"><img src="docs/assets/demos/part-features/test_holes_at_several_points-motion.gif" alt="A plate of Hole Wizard holes placed from points, a mirror and a ring" width="100%"></a><br><sub>A plate of Hole Wizard holes from points, a mirror and a ring</sub></td>
<td width="33%" valign="top"><a href="https://andrewbartels1.com/SolidworksMCP-python/demos/#wrench"><img src="docs/assets/demos/equations/test_a_combination_wrench_sized_by_one_variable-motion.gif" alt="A steel combination wrench sized by one global variable and lettered with its size: 13 mm, then 19 mm, then 8 mm in its own configuration" width="100%"></a><br><sub>One variable sizes a combination wrench: equations and configurations</sub></td>
<td width="33%" valign="top"><a href="https://andrewbartels1.com/SolidworksMCP-python/demos/#boolean-logic"><img src="docs/assets/demos/multi-body/test_boolean_logic_on_a_cube_and_a_sphere-motion.gif" alt="A cube and a sphere as separate bodies: joined, each cut by the other, their common quarter, and the exclusive or" width="100%"></a><br><sub>Boolean logic on a cube and a sphere: every combine of two bodies</sub></td>
</tr>
</table>

Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
6 changes: 3 additions & 3 deletions docs/assets/progress/tool-list-size.md
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
| `SOLIDWORKS_MCP_TOOLSETS` | `SOLIDWORKS_MCP_TOOL_MODE` | Tools listed | Size | Tokens (estimate) | Of the full list |
| --- | --- | ---: | ---: | ---: | ---: |
| `all` | `list` | 173 | 284 KB | 72,744 | 100% |
| `all` | `list` | 173 | 284 KB | 72,811 | 100% |
| `core` | `list` | 132 | 206 KB | 52,841 | 73% |
| `drawing` | `list` | 22 | 39 KB | 10,074 | 14% |
| `drawing` | `list` | 22 | 40 KB | 10,141 | 14% |
| `automation` | `list` | 3 | 6 KB | 1,556 | 2% |
| `vba` | `list` | 10 | 17 KB | 4,356 | 6% |
| `docs` | `list` | 6 | 15 KB | 3,916 | 5% |
| `core,drawing` | `list` | 154 | 246 KB | 62,915 | 86% |
| `core,drawing` | `list` | 154 | 246 KB | 62,982 | 87% |
| `all` | `search` | 4 | 4 KB | 908 | 1% |
| `core` | `search` | 4 | 4 KB | 908 | 1% |
26 changes: 26 additions & 0 deletions docs/demos.md
Original file line number Diff line number Diff line change
Expand Up @@ -743,6 +743,32 @@ from 30 to 15 mm in every view. A scale of 0:2 is refused.
2. `set_sheet_scale({"numerator": 1, "denominator": 2})`
3. `set_sheet_scale({"numerator": 0, "denominator": 2})`: `invalid_input`

### A view keeps the sheet's scale {#view-keeps-scale}

![create_drawing_view adding an angle bracket's front, top and right views to an A3 sheet set to 1:2, the sheet still 1:2 afterwards; then, with fit_sheet_scale, SolidWorks's own 2:1 kept](assets/demos/drawing-package/test_a_view_on_a_half_scale_sheet-motion.gif)

> *Example prompt:* On this 1:2 A3 sheet, add the bracket's front, top and
> right views.

**What it shows.** SolidWorks sets a sheet's scale to its own choice when
the first view goes on, which here would turn a 1:2 sheet into 2:1.
`create_drawing_view` now keeps the scale the sheet had and says so in its
message; `fit_sheet_scale` keeps SolidWorks's choice instead:

| Step | Tools | Expected | Measured |
| --- | --- | --- | --- |
| An A3 sheet set to 1:2 | `update_sheet_format`, `set_sheet_scale` | 1:2 | 1:2 |
| The bracket's front view | `create_drawing_view` | the sheet stays 1:2 | "kept its scale 1:2 (SolidWorks had changed it to 2:1)" |
| Its top and right views | `create_drawing_view` | still 1:2 | 1:2 |
| A new 1:2 sheet, the front view with `fit_sheet_scale` | `create_drawing_view` | SolidWorks's 2:1, the view on the sheet | 2:1, `fits_sheet` true |

**Tool calls**

1. A 60 x 40 x 40 mm angle bracket with three M6 holes, saved
2. `create_drawing`, `update_sheet_format({"sheet_format": "a3 - iso"})`, `set_sheet_scale({"numerator": 1, "denominator": 2})`
3. `create_drawing_view({"model_path": "...", "view_type": "front", "position_x": 140})`, then the top and right views
4. On a new drawing set up the same way: `create_drawing_view({"model_path": "...", "view_type": "front", "position_x": 140, "fit_sheet_scale": true})`

### A BOM on an assembly drawing {#bom}

![insert_bom_table adding a BOM that lists both parts of a two-part assembly](assets/demos/drawing-package/test_insert_bom_table_lists_both_parts.gif)
Expand Down
1 change: 1 addition & 0 deletions docs/user-guide/tool-catalog/drawing.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ Place one named view of a part or assembly on the active drawing sheet.
| `scale` | `float?` | — | `None` | The view's own scale, e.g. `0.5` for 1:2 (`UseSheetScale` off, `ScaleDecimal`, read back as `scale_applied`); left out, the sheet's scale (`set_sheet_scale`) |
| `orientation` | `str?` | — | `None` | View orientation (front, top, right, isometric); left out, a `view_type` that names one is used, else front |
| `exploded` | `bool` | — | `False` | Show the assembly's exploded view (`create_exploded_view`) in this view (`IView.ShowExploded`) |
| `fit_sheet_scale` | `bool` | — | `False` | Let SolidWorks rescale the sheet to fit the first view on it (its "Automatically scale new drawing views" option); by default the sheet keeps its scale and the reply gives `sheet_scale`, `sheet_rescale_undone` and `fits_sheet` |

**Sample call:**

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
schema: spec-driven
created: 2026-11-28
27 changes: 27 additions & 0 deletions openspec/changes/drawing-view-keeps-sheet-scale/design.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
## Context

Probe, SolidWorks 2026 SP4, 2026-11-28: `GetUserPreferenceToggle(86)`
(`swAutomaticScaling3ViewDrawings`) was true. A new drawing's sheet set to
1:2 with `ISheet.SetScale(1, 2, True, False)` read 2:1 after
`CreateDrawViewFromModelView3` placed the first view of a 30 mm block.
`SetScale(1, 2, ...)` then `EditRebuild3` put it back and the view shrank
with it; a second view did not rescale the sheet.

## Goals / Non-Goals

**Goals:** a scale set on a sheet holds when views are placed.

**Non-Goals:** changing the user's SolidWorks option; choosing a scale for
the agent (`generate_drawing_package` already does).

## Decisions

1. **Set back, not switch off.** The scale read before the view is set back
after it, rather than turning option 86 off and on: that is a system
setting the user owns, and a failure between the two calls would leave it
changed.
2. **Tell, don't refuse.** A view that no longer fits the paper at the kept
scale is still placed; `fits_sheet` false says so, and the message points
to `set_sheet_scale` or `fit_sheet_scale`.
3. **Default keep.** Keeping is the default because the agent can see and set
the sheet's scale; a silent change it can't see is the bug.
35 changes: 35 additions & 0 deletions openspec/changes/drawing-view-keeps-sheet-scale/proposal.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
## Why

`create_drawing_view` changed the sheet's scale behind the agent's back. With
SolidWorks's system option "Automatically scale new drawing views" on (the
default), the first view placed on an empty sheet rescales the sheet to fit
it: on 2026-11-28 a sheet set to 1:2 read 2:1 after a front view of a 30 mm
block was placed, so the view was four times the size asked for. A scale set
with `add_sheet` or `set_sheet_scale` should hold.

## What Changes

- `create_drawing_view` (and `add_drawing_view`) keep the active sheet's
scale: when SolidWorks rescales the sheet while placing the view, the scale
is set back. The reply gives `sheet_scale`, `sheet_rescale_undone` (the
scale SolidWorks chose, or null) and `fits_sheet` (whether the view lies
on the paper).
- A new input `fit_sheet_scale` (default false) lets SolidWorks fit the
sheet to the first view, as before.
- The user's SolidWorks option is never changed.

## Capabilities

### New Capabilities

- `tools/drawing-view-placement`: the sheet scale around a placed view.

### Modified Capabilities

None.

## Impact

- `adapters/solidworks/io.py` (`_place_view`), the mock's `_mock_place_view`,
`tools/drawing.py` (`CreateDrawingViewInput.fit_sheet_scale`).
- Tests beside each module; a live test.
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
## ADDED Requirements

### Requirement: A placed view keeps the sheet's scale
`create_drawing_view` SHALL leave the active sheet's scale as it was before
the view was placed, setting it back when SolidWorks rescaled the sheet, and
SHALL reply with `sheet_scale` (e.g. `"1:2"`), `sheet_rescale_undone` (the
scale SolidWorks had chosen, or null when it chose none) and `fits_sheet`
(whether the view's outline lies on the paper, or null when unread). With
`fit_sheet_scale` true it SHALL keep the scale SolidWorks chose. It SHALL NOT
change SolidWorks's own options.

#### Scenario: A first view on a 1:2 sheet
- **WHEN** a front view of a 30 mm block is placed on an empty sheet at 1:2
while SolidWorks's automatic view scaling is on
- **THEN** the sheet reads 1:2 afterwards, `sheet_rescale_undone` names the
scale SolidWorks had chosen, and `fits_sheet` is true

#### Scenario: Letting SolidWorks fit the sheet
- **WHEN** the same view is placed with `fit_sheet_scale` true
- **THEN** the sheet keeps the scale SolidWorks chose and
`sheet_rescale_undone` is null
16 changes: 16 additions & 0 deletions openspec/changes/drawing-view-keeps-sheet-scale/tasks.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
## 1. Build

- [x] 1.1 `_place_view`: read the sheet scale before, set it back after
unless `fit_sheet_scale`; reply `sheet_scale`, `sheet_rescale_undone`,
`fits_sheet`
- [x] 1.2 Mock and tool input `fit_sheet_scale`; the tool's message names a
view off the paper

## 2. Tests

- [x] 2.1 Unit tests beside each module, 100% coverage
- [x] 2.2 Live test `tests/live/test_live_sw_drawing_view_scale.py`

## 3. Docs

- [x] 3.1 CHANGELOG; tool catalog entry
3 changes: 3 additions & 0 deletions src/solidworks_mcp/adapters/mock_adapter.py
Original file line number Diff line number Diff line change
Expand Up @@ -3323,6 +3323,9 @@ def _mock_place_view(self, payload: Any) -> AdapterResult[dict[str, Any]]:
},
"views_before": before,
"views_after": len(self._drawing_views),
"sheet_scale": "1:1",
"sheet_rescale_undone": None,
"fits_sheet": True,
},
execution_time=self._delays["model_operation"],
)
Expand Down
73 changes: 73 additions & 0 deletions src/solidworks_mcp/adapters/solidworks/io.py
Original file line number Diff line number Diff line change
Expand Up @@ -217,6 +217,51 @@ def _view_names(adapter: Any, drawing: Any) -> list[str]:
return names


def _sheet_reading(adapter: Any, drawing: Any) -> tuple[Any, list[float] | None]:
"""The active sheet and its ``GetProperties2`` values, or None unread.

Args:
adapter: A connected ``PyWin32Adapter``.
drawing: The drawing document, flagged for ``IDrawingDoc``.

Returns:
tuple: The sheet (``ISheet``) and its properties: paper size, template,
scale numerator and denominator, first angle, width and height (m).
"""
sheet = adapter._attempt(
lambda: _sw_type_info.flagged(drawing.GetCurrentSheet(), "ISheet"),
default=None,
)
props = adapter._attempt(lambda: sheet.GetProperties2(), default=None)
if isinstance(props, (list, tuple)) and len(props) >= 7:
return sheet, [float(v) for v in props[:7]]
return sheet, None


def _scale_text(props: list[float]) -> str:
"""A sheet's scale as ``"1:2"`` from its properties."""
return f"{props[2]:g}:{props[3]:g}"


def _on_paper(adapter: Any, view: Any, props: list[float]) -> bool | None:
"""Whether a view's outline lies on the sheet's paper, or None unread.

Args:
adapter: A connected ``PyWin32Adapter``.
view: The placed view (``IView``), or None.
props: The sheet's ``GetProperties2`` values; width and height in m.

Returns:
bool | None: True when the outline is inside the paper.
"""
wrapped: Any = _as_com(adapter, view, "IView") if view is not None else None
outline = adapter._attempt(lambda: wrapped.GetOutline(), default=None)
if not (isinstance(outline, (list, tuple)) and len(outline) >= 4):
return None
x0, y0, x1, y1 = (float(v) for v in outline[:4])
return x0 >= 0 and y0 >= 0 and x1 <= props[5] and y1 <= props[6]


def _component_transforms(adapter: Any, assembly: Any) -> dict[str, tuple[float, ...]]:
"""Snapshot every component's placement, for before/after comparison.

Expand Down Expand Up @@ -3447,6 +3492,7 @@ def _place_view(self, payload: Any) -> AdapterResult[dict[str, Any]]:
def _add() -> dict[str, Any]:
drawing = _sw_type_info.flagged(adapter.currentModel, "IDrawingDoc")
before = _view_names(adapter, drawing)
_, sheet_before = _sheet_reading(adapter, drawing)

# The model has to be loaded before a view of it can be placed,
# and OpenDoc6's errors/warnings out-params must be byref VARIANTs
Expand Down Expand Up @@ -3519,6 +3565,30 @@ def _add() -> dict[str, Any]:
scale_read, scale, rel_tol=1e-6
)

# SolidWorks's "Automatically scale new drawing views" option
# rescales an empty sheet to fit its first view (a 1:2 sheet read
# 2:1). The scale is set back unless the caller asked for the fit;
# the user's option itself is never touched.
sheet, sheet_after = _sheet_reading(adapter, drawing)
rescale_undone = None
if (
sheet_before is not None
and sheet_after is not None
and sheet_after[2:4] != sheet_before[2:4]
and not _first(data, "fit_sheet_scale", default=False)
):
rescale_undone = _scale_text(sheet_after)
kept = sheet_before
adapter._attempt(
lambda: sheet.SetScale(kept[2], kept[3], True, False),
default=None,
)
adapter._attempt(
lambda: adapter.currentModel.EditRebuild3(), default=None
)
_, sheet_after = _sheet_reading(adapter, drawing)
fits_sheet = _on_paper(adapter, view, sheet_after) if sheet_after else None

shows_exploded = None
if _first(data, "exploded", default=False):
shown = _as_com(adapter, view, "IView") if view is not None else None
Expand All @@ -3539,6 +3609,9 @@ def _add() -> dict[str, Any]:
"scale_read": scale_read,
"views_before": len(before),
"views_after": len(after),
"sheet_scale": _scale_text(sheet_after) if sheet_after else None,
"sheet_rescale_undone": rescale_undone,
"fits_sheet": fits_sheet,
}

return cast(
Expand Down
37 changes: 34 additions & 3 deletions src/solidworks_mcp/tools/drawing.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ class CreateDrawingViewInput(BaseModel):
scale (float | None): The view's own scale; none uses the sheet's.
view_type (str): The view type value.
exploded (bool): Show the assembly's exploded view.
fit_sheet_scale (bool): Let SolidWorks rescale the sheet to fit the view.
"""

model_path: str = Field(description="Path to the SolidWorks model file")
Expand All @@ -59,6 +60,35 @@ class CreateDrawingViewInput(BaseModel):
description="Show the assembly's exploded view (create_exploded_view) in "
"this view",
)
fit_sheet_scale: bool = Field(
default=False,
description="Let SolidWorks rescale the sheet to fit the first view on it; "
"by default the sheet keeps its scale (set_sheet_scale)",
)


def _view_message(input_data: CreateDrawingViewInput, data: dict[str, Any]) -> str:
"""The reply message for a placed view, naming a kept scale or an overflow.

Args:
input_data: The view that was asked for.
data: The adapter's reply data.

Returns:
str: The message.
"""
message = f"Created {input_data.view_type} view of {input_data.model_path}"
if data.get("sheet_rescale_undone"):
message += (
f"; the sheet kept its scale {data.get('sheet_scale')} (SolidWorks had "
f"changed it to {data['sheet_rescale_undone']})"
)
if data.get("fits_sheet") is False:
message += (
"; the view runs off the paper: set a smaller scale with "
"set_sheet_scale, or place it with fit_sheet_scale"
)
return message


class AddDimensionInput(CompatInput):
Expand Down Expand Up @@ -451,8 +481,9 @@ async def create_drawing_view(input_data: CreateDrawingViewInput) -> dict[str, A
`create_technical_drawing`, and for a whole drawing from a model, use
`generate_drawing_package`.
Needs: an open, active drawing and the model file on disk. Changes: adds a view
to the sheet. Returns: `data` with the view's `name`, `orientation`, `position`,
`scale` and the view counts before and after.
to the sheet; the sheet keeps its scale unless `fit_sheet_scale`. Returns: `data`
with the view's `name`, `orientation`, `position`, `scale`, `sheet_scale`,
`fits_sheet` and the view counts before and after.

Args:
input_data: The view. `model_path` and `view_type` (front, back, left, right, top, bottom, isometric (iso), trimetric, dimetric or current) are
Expand All @@ -472,7 +503,7 @@ async def create_drawing_view(input_data: CreateDrawingViewInput) -> dict[str, A
require_success(result, "Failed to create drawing view")
return {
"status": "success",
"message": f"Created {input_data.view_type} view of {input_data.model_path}",
"message": _view_message(input_data, result.data or {}),
"data": result.data,
"execution_time": result.execution_time,
}
Expand Down
Loading
Loading