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
11 changes: 11 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,17 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## [Unreleased]

### Changed

- **`generate_drawing_package` fits every title-block field** (#158):
not just DWG NO. and TITLE but every field the sheet format fills from a
property (material, drawn by, company...), each listed in the reply's
`title_block`.
- **`subtitle` is the TITLE's second line, not the company** (#158):
ISO 7200 treats it as the supplementary title under the title, and the
company field as the legal owner's name only. The TITLE is set at 60% of
the format's height so both lines fit.

### Added

- **`save_body_as_part` leaves no extra assembly open** (queue item 27,
Expand Down
2 changes: 1 addition & 1 deletion docs/assets/progress/progress.json
Original file line number Diff line number Diff line change
Expand Up @@ -998,7 +998,7 @@
"total": 2838
},
"api": {
"covered": 277,
"covered": 278,
"total": 5985
},
"interfaces": [
Expand Down
2 changes: 1 addition & 1 deletion docs/assets/progress/progress.svg
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` | 140 | 227 KB | 58,124 | 100% |
| `all` | `list` | 140 | 227 KB | 58,160 | 100% |
| `core` | `list` | 100 | 151 KB | 38,717 | 67% |
| `drawing` | `list` | 21 | 37 KB | 9,580 | 16% |
| `drawing` | `list` | 21 | 38 KB | 9,616 | 17% |
| `automation` | `list` | 3 | 6 KB | 1,556 | 3% |
| `vba` | `list` | 10 | 17 KB | 4,356 | 7% |
| `docs` | `list` | 6 | 15 KB | 3,914 | 7% |
| `core,drawing` | `list` | 121 | 189 KB | 48,297 | 83% |
| `core,drawing` | `list` | 121 | 189 KB | 48,333 | 83% |
| `all` | `search` | 4 | 4 KB | 908 | 2% |
| `core` | `search` | 4 | 4 KB | 908 | 2% |
6 changes: 4 additions & 2 deletions docs/user-guide/tool-catalog/drawing-automation.md
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,8 @@ Set the active drawing sheet's scale, e.g. 1:2; views that use the sheet scale f

Create a complete A3 drawing of a part or assembly in one call, and save it with a PDF.

Every title-block field the sheet format fills from a property (DWG NO., TITLE, material, drawn by and the rest) is shrunk until it fits its box; the reply's `title_block` lists each one with `fits` and its text height before and after.

**Prerequisite:** SolidWorks running

**Parameters:**
Expand All @@ -107,15 +109,15 @@ Create a complete A3 drawing of a part or assembly in one call, and save it with
| `model_path` | `str` | ✅ | | Full path to the .SLDPRT or .SLDASM |
| `output_dir` | `str?` | — | `null` | Where to save the drawing; the model's folder when omitted |
| `title` | `str?` | — | `null` | Short title, e.g. 'Mounting Plate - Rev A'; the file name when omitted |
| `subtitle` | `str?` | — | `null` | Sheet title, e.g. 'Base support' |
| `subtitle` | `str?` | — | `null` | A second, smaller line under the TITLE (ISO 7200's supplementary title), e.g. 'Base support' |
| `drawing_number` | `str?` | — | `null` | DWG NO., also the drawing file name, e.g. 'MP-RevA-01' |
| `author` | `str` | — | `""` | DRAWN name |
| `revision` | `str` | — | `"A"` | Revision letter |
| `company` | `str` | — | `""` | Company name |
| `notes` | `list[str]` | — | `[]` | Extra note lines (material, process, connections); 3-7 lines in total |
| `include_isometric` | `bool` | — | `true` | Add an isometric view |
| `write_model_properties` | `bool` | — | `true` | Write Description/Material/Weight into the model so the title block shows them, and save it |
| `title_block_text_height_mm` | `float?` | — | `null` | Largest text height (mm) for the title block's DWG NO. and TITLE, e.g. 3 for smaller text. By default they keep the sheet format's height and are only shrunk to fit their boxes. |
| `title_block_text_height_mm` | `float?` | — | `null` | Largest text height (mm) for the title block's fields (DWG NO., TITLE and every other field the format fills from a property), e.g. 3 for smaller text. By default they keep the sheet format's height and are only shrunk to fit their boxes. |
| `include_bom` | `bool` | — | `false` | Assemblies only: put a bill of materials in the top of the isometric view's cell, with the isometric fitted below it |

**Sample call:**
Expand Down
2 changes: 2 additions & 0 deletions openspec/changes/title-block-fit-every-field/.openspec.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
schema: spec-driven
created: 2026-11-17
45 changes: 45 additions & 0 deletions openspec/changes/title-block-fit-every-field/proposal.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
## Why

`generate_drawing_package` shrinks the title block's DWG NO. and TITLE text
until each fits its box, but no other field. A long material name, company
or DRAWN BY value runs over the next cell the same way (#158, "Only two
fields are fitted"). The two fitted fields are named in code; every other
field is left as the format draws it.

## What Changes

- The title-block step fits **every field the sheet format links to a
property** (`$PRP:"..."` or `$PRPSHEET:"..."`), the same way the two
fitted today are: shrunk until its text ends before the next note in its
row, never below the minimum height, and capped by
`title_block_text_height_mm` when given.
- The reply's `title_block` lists each fitted field. The two fitted today
keep their names (`drawing number`, `title`); the drawing's own fields
use the names `update_title_block` takes (`drawn by`, `drawn date`,
`revision`, `company`); any other is named by its property, as the format
links it (e.g. `SW-Material`).
- A property the format shows twice is fitted once.

Out of scope: measuring against the format's cell lines instead of the
next note (#158's first point), and where `subtitle` goes (#158's third
point, a decision for the user).

## Capabilities

### New Capabilities

- `tools/drawing-package-title-block`: how the generated drawing's title
block fields are fitted to their boxes.

### Modified Capabilities

None.

## Impact

- `adapters/solidworks/drawing_standard.py` (`_fit_title_block`, a helper
reading the linked property); its unit tests.
- `generate_drawing_package`'s catalog entry, the CHANGELOG, the queue.
- Live: the existing `test_generate_drawing_package_on_a_block` evidence
shows every field fitted.
- #158 (part of it).
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
## Purpose

The drawing `generate_drawing_package` builds has a title block whose
fields each fit their box, whatever the values' lengths.

## ADDED Requirements

### Requirement: Every linked field fits its box
The title-block step SHALL fit every sheet-format note linked to a property
(`$PRP:"name"` or `$PRPSHEET:"name"`): its text SHALL be shrunk until it
ends before the next note in its row (or the title block's right edge),
no smaller than the minimum height, and no larger than
`title_block_text_height_mm` when that is given. A property shown by more
than one note SHALL be fitted once, by its first note.

#### Scenario: A long material name
- **WHEN** the part's material name is longer than its cell
- **THEN** the reply's `title_block` has an entry for it with `fits` true,
and its text height is below the format's

#### Scenario: A short value
- **WHEN** a field's value already fits
- **THEN** its entry has `fits` true and the same height before and after

### Requirement: Each fitted field is named in the reply
The reply's `title_block` SHALL name the DWG NO. `drawing number` and the
TITLE `title`; the drawing's own fields SHALL use the names
`update_title_block` takes, with spaces (`drawn by`, `drawn date`,
`revision`, `company`); any other field SHALL be named by its property.

#### Scenario: The ISO A3 format
- **WHEN** a drawing is generated on `a3 - iso`
- **THEN** `title_block` lists `drawing number` and `title`, and an entry
for each other property the format links

### Requirement: The subtitle is the TITLE's second line
A `subtitle` SHALL be shown as a second line of the TITLE field (ISO 7200's
supplementary title), with the TITLE's text height at most 60% of the
format's (or the caller's cap, if smaller). The company field SHALL show
`company` only.

#### Scenario: A subtitle and no company
- **WHEN** `subtitle` is `Base support` and `company` is empty
- **THEN** the TITLE reads `Package Block` then `Base support`, and the
company field is empty
18 changes: 18 additions & 0 deletions openspec/changes/title-block-fit-every-field/tasks.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
## 1. Fit

- [x] 1.1 `_fit_title_block` fits every linked note after the two named fields; a property shown twice is fitted once; names from `update_title_block`'s fields, else the property; unit tests (a long linked field shrunk, a short one unchanged, a duplicate fitted once, a note with no link left alone)

## 1b. Subtitle (the user's question on #158: follow standard practice)

- [x] 1b.1 ISO 7200: `subtitle` is the supplementary title, the TITLE's second line; the company field holds `company` only; the TITLE at 60% of the format's height (or the caller's cap); unit tests
- [ ] 1b.2 Live: the drawing test passes a subtitle and checks the TITLE's two lines

## 2. Docs

- [x] 2.1 `generate_drawing_package`'s catalog entry, CHANGELOG, queue row 31
- [x] 2.2 Full mock suite at 100% coverage, ruff, mypy, `mkdocs build --strict`

## 3. Live

- [ ] 3.1 `test_generate_drawing_package_on_a_block` asserts every listed field fits; run by the user
- [ ] 3.2 Archive after the user's pass
1 change: 1 addition & 0 deletions openspec/queue.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ Last updated 2026-11-16.
| 26 | `execute_macro` runs VBA source text (a `generate_vba_*` result, or the agent's own), saved as a `.swb` and run with the dialog watchdog. Opt-in (`SOLIDWORKS_MCP_ALLOW_VBA_SOURCE`), the user's choice 2026-11-17 | #96 | `macro-from-vba-source` (archived) | Done 2026-11-17 (#246), checked live |
| 27 | `save_body_as_part` leaves an extra unsaved assembly open (the Save Bodies feature's create-assembly option) | #101 | `save-body-no-stray-assembly` (archived) | Done 2026-11-17 (#247), checked live: the stray `Assem<N>` is closed |
| 28 | Restricted VBA source: `SOLIDWORKS_MCP_ALLOW_VBA_SOURCE` = off / restricted / full; `restricted` checks the source against the SolidWorks type library and a blocklist before it runs, with every default and option disclosed in the docs (the user's choice 2026-11-17) | none | `vba-source-restricted` (archived) | Done 2026-11-17 (#248), checked live: restricted source runs, a `Shell` line is refused, `off` refuses |
| 31 | `generate_drawing_package` fits every title-block field the sheet format fills from a property, not just DWG NO. and TITLE | #158 (part) | `title-block-fit-every-field` | Built, unit-tested; checked live 2026-11-18 (`test_live_sw_drawing_package_tools.py::test_generate_drawing_package_on_a_block`) |
## Removed tools (item 10, release 2.1.0)

33 tools were registered but never implemented: every call returned
Expand Down
79 changes: 74 additions & 5 deletions src/solidworks_mcp/adapters/solidworks/drawing_standard.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
import glob
import ntpath
import os
import re
from dataclasses import dataclass, field
from datetime import date as _date
from typing import TYPE_CHECKING, Any, cast
Expand Down Expand Up @@ -263,7 +264,8 @@ def title_block_properties(
The ``a3 - iso`` format reads TITLE, MATERIAL and WEIGHT from the model
(``$PRPSHEET``) and DRAWN, REVISION and the company from the drawing
(``$PRP``). Material and weight are links, so they always show the model's
real values.
real values. ``subtitle`` is not a property: the title-block step writes it
as the TITLE's second line (ISO 7200's supplementary title).

Returns:
tuple: (model properties, drawing properties).
Expand All @@ -280,7 +282,9 @@ def title_block_properties(
"DrawnBy": author,
"DrawnDate": drawn_date,
"Revision": revision,
"COMPANYNAME": company or (subtitle or ""),
# ISO 7200: the company field is the legal owner's name only; a
# subtitle is the supplementary title, shown under the TITLE.
"COMPANYNAME": company,
}
return model_props, {k: v for k, v in drawing_props.items() if v}

Expand Down Expand Up @@ -317,6 +321,25 @@ def find_sheet_format(adapter: Any, name: str = "a3 - iso.slddrt") -> str | None
#: default drawing number ran across the size box at the format's height).
TITLE_BLOCK_FIELDS = {"SW-File Name": "drawing number", "Description": "title"}

#: Every other linked field is fitted too, named as ``update_title_block``
#: names the drawing's own fields, or else by its property.
OTHER_FIELD_NAMES = {
"DrawnBy": "drawn by",
"DrawnDate": "drawn date",
"Revision": "revision",
"COMPANYNAME": "company",
}

#: The property a sheet-format note shows: ``$PRP:"name"`` or ``$PRPSHEET:"name"``.
_LINKED_PROPERTY = re.compile(r'\$PRP(?:SHEET)?:"([^"]+)"', re.IGNORECASE)


def linked_property(linked: str) -> str | None:
"""The first property a note's linked text shows, or None."""
match = _LINKED_PROPERTY.search(linked)
return match.group(1) if match else None


#: A fitted field's text is never made smaller than this.
MIN_FIELD_HEIGHT = 0.002

Expand Down Expand Up @@ -444,6 +467,7 @@ class _Sheet:
title_block: Field name -> how it was fitted to its box.
format_links: The property links the sheet format's notes show.
field_height: The caller's cap on the fitted fields' text height.
subtitle: The supplementary title, shown under the TITLE.
"""

path: str
Expand All @@ -467,6 +491,12 @@ class _Sheet:
title_block: dict[str, dict[str, Any]] = field(default_factory=dict)
format_links: list[str] = field(default_factory=list)
field_height: float | None = None
subtitle: str | None = None


#: A TITLE with a subtitle line is set at this share of the format's height,
#: so both lines fit in about the room one line had.
SUBTITLE_HEIGHT_SHARE = 0.6


def _step(steps: list[dict[str, Any]], name: str, result: AdapterResult[Any]) -> None:
Expand Down Expand Up @@ -1599,8 +1629,28 @@ def apply(h: float) -> Box | None:
"room_ends_mm": round(right * 1000, 1),
}

def _add_subtitle(
self, note: Any, linked: str, subtitle: str, cap: float | None
) -> float | None:
"""Write ``subtitle`` as the TITLE note's second line.

Returns:
The text-height cap for the two lines: the caller's, or else
:data:`SUBTITLE_HEIGHT_SHARE` of the format's height.
"""
text = linked + "\r\n" + subtitle # SolidWorks notes break lines with CR LF
self._attempt(lambda: note.SetText(text), default=None)
height = self._attempt(lambda: note.GetTextFormat().CharHeight, default=None)
if not isinstance(height, (int, float)) or height <= 0:
return cap
shared = float(height) * SUBTITLE_HEIGHT_SHARE
return shared if cap is None else min(cap, shared)

def _fit_title_block(self, s: _Sheet) -> dict[str, dict[str, Any]]:
"""Fit the DWG NO. and TITLE fields of the sheet format to their boxes.
"""Fit the sheet format's title-block fields to their boxes.

DWG NO. and TITLE first, by name, then every other note linked to a
property, each once.

Edits the sheet format (``EditTemplate``), always returning to the
sheet (``EditSheet``). Run after the drawing is saved: the DWG NO.
Expand All @@ -1619,11 +1669,29 @@ def _fit_title_block(self, s: _Sheet) -> dict[str, dict[str, Any]]:
if match is None or match[2] is None:
s.title_block[name] = {"found": match is not None, "fits": None}
continue
cap = s.field_height
if prop == "Description" and s.subtitle:
cap = self._add_subtitle(match[0], match[1], s.subtitle, cap)
others = [n[2] for n in notes if n is not match and n[2] is not None]
right = field_room(match[2], others, TITLE_BLOCK[2])
s.title_block[name] = {
"found": True,
**self._fit_field(match[0], right, s.field_height),
**self._fit_field(match[0], right, cap),
}
fitted = set(TITLE_BLOCK_FIELDS)
for note, linked, box in notes:
shown = linked_property(linked)
if shown is None or shown in fitted or box is None:
continue
fitted.add(shown)
name = OTHER_FIELD_NAMES.get(shown, shown)
if name in s.title_block: # a property named "title", say
name = linked
others = [n[2] for n in notes if n[0] is not note and n[2] is not None]
right = field_room(box, others, TITLE_BLOCK[2])
s.title_block[name] = {
"found": True,
**self._fit_field(note, right, s.field_height),
}
finally:
self._attempt(lambda: drawing.EditSheet(), default=None)
Expand Down Expand Up @@ -1751,7 +1819,7 @@ async def create_standard_drawing(
model_path: Part (.SLDPRT) or assembly (.SLDASM) to draw.
output_dir: Folder for the .SLDDRW and PDF; the model's folder by default.
title: Title block TITLE; the model file name by default.
subtitle: Company field when ``company`` is empty.
subtitle: The supplementary title, the TITLE's second line.
drawing_number: DWG NO.; also the drawing file name. Default
``<MODEL>-Rev<revision>-01``.
author: DRAWN name.
Expand Down Expand Up @@ -1877,6 +1945,7 @@ def failed(error: str) -> AdapterResult[dict[str, Any]]:
include_bom=include_bom,
material=material,
extra_notes=list(notes or []),
subtitle=(subtitle or "").strip() or None,
field_height=(
title_block_text_height_mm / 1000.0
if title_block_text_height_mm
Expand Down
15 changes: 9 additions & 6 deletions src/solidworks_mcp/tools/drawing_automation.py
Original file line number Diff line number Diff line change
Expand Up @@ -187,15 +187,15 @@ class GenerateDrawingPackageInput(CompatInput):
model_path (str): Part or assembly to draw.
output_dir (str | None): Folder for the .SLDDRW and PDF.
title (str | None): Title block TITLE (short).
subtitle (str | None): Sheet title.
subtitle (str | None): The TITLE's second line.
drawing_number (str | None): DWG NO. and file name.
author (str): DRAWN name.
revision (str): Revision letter.
company (str): Company name field.
notes (list[str]): Extra note lines.
include_isometric (bool): Add the isometric view.
write_model_properties (bool): Write title-block properties into the model.
title_block_text_height_mm (float | None): Cap on DWG NO./TITLE text height.
title_block_text_height_mm (float | None): Cap on the title-block fields' text height.
include_bom (bool): Put a BOM above the isometric view (assemblies).
"""

Expand All @@ -209,7 +209,9 @@ class GenerateDrawingPackageInput(CompatInput):
description="Short title, e.g. 'Mounting Plate - Rev A'; the file name when omitted",
)
subtitle: str | None = Field(
default=None, description="Sheet title, e.g. 'Base support'"
default=None,
description="A second, smaller line under the TITLE (ISO 7200's "
"supplementary title), e.g. 'Base support'",
)
drawing_number: str | None = Field(
default=None,
Expand All @@ -230,9 +232,10 @@ class GenerateDrawingPackageInput(CompatInput):
title_block_text_height_mm: float | None = Field(
default=None,
gt=0,
description="Largest text height (mm) for the title block's DWG NO. and "
"TITLE, e.g. 3 for smaller text. By default they keep the sheet "
"format's height and are only shrunk to fit their boxes.",
description="Largest text height (mm) for the title block's fields (DWG "
"NO., TITLE and every other field the format fills from a property), "
"e.g. 3 for smaller text. By default they keep the sheet format's "
"height and are only shrunk to fit their boxes.",
)
include_bom: bool = Field(
default=False,
Expand Down
Loading
Loading