From c1529ded76f402b0af93f41e020efba5958a7c15 Mon Sep 17 00:00:00 2001 From: Andrew Bartels Date: Tue, 17 Nov 2026 21:04:42 -0800 Subject: [PATCH 1/2] fix: generate_drawing_package fits every title-block field Not just DWG NO. and TITLE: every field the sheet format fills from a property (material, drawn by, company...) is shrunk until it fits its box, and each is listed in the reply's title_block (#158). --- CHANGELOG.md | 7 ++ docs/assets/progress/tool-list-size.md | 6 +- .../tool-catalog/drawing-automation.md | 4 +- .../.openspec.yaml | 2 + .../title-block-fit-every-field/proposal.md | 45 +++++++++++++ .../tools/drawing-package-title-block/spec.md | 34 ++++++++++ .../title-block-fit-every-field/tasks.md | 13 ++++ openspec/queue.md | 1 + .../adapters/solidworks/drawing_standard.py | 40 +++++++++++- .../tools/drawing_automation.py | 9 +-- .../test_live_sw_drawing_package_tools.py | 4 ++ .../test_drawing_standard_generator.py | 64 +++++++++++++++++++ 12 files changed, 220 insertions(+), 9 deletions(-) create mode 100644 openspec/changes/title-block-fit-every-field/.openspec.yaml create mode 100644 openspec/changes/title-block-fit-every-field/proposal.md create mode 100644 openspec/changes/title-block-fit-every-field/specs/tools/drawing-package-title-block/spec.md create mode 100644 openspec/changes/title-block-fit-every-field/tasks.md diff --git a/CHANGELOG.md b/CHANGELOG.md index 320a2e6d..1deb7735 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -12,6 +12,13 @@ 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`. + ### Added - **`save_body_as_part` leaves no extra assembly open** (queue item 27, diff --git a/docs/assets/progress/tool-list-size.md b/docs/assets/progress/tool-list-size.md index 95fdedab..73232e79 100644 --- a/docs/assets/progress/tool-list-size.md +++ b/docs/assets/progress/tool-list-size.md @@ -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,142 | 100% | | `core` | `list` | 100 | 151 KB | 38,717 | 67% | -| `drawing` | `list` | 21 | 37 KB | 9,580 | 16% | +| `drawing` | `list` | 21 | 37 KB | 9,598 | 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,315 | 83% | | `all` | `search` | 4 | 4 KB | 908 | 2% | | `core` | `search` | 4 | 4 KB | 908 | 2% | diff --git a/docs/user-guide/tool-catalog/drawing-automation.md b/docs/user-guide/tool-catalog/drawing-automation.md index d16257eb..73fcd2e0 100644 --- a/docs/user-guide/tool-catalog/drawing-automation.md +++ b/docs/user-guide/tool-catalog/drawing-automation.md @@ -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:** @@ -115,7 +117,7 @@ Create a complete A3 drawing of a part or assembly in one call, and save it with | `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:** diff --git a/openspec/changes/title-block-fit-every-field/.openspec.yaml b/openspec/changes/title-block-fit-every-field/.openspec.yaml new file mode 100644 index 00000000..bbe8b393 --- /dev/null +++ b/openspec/changes/title-block-fit-every-field/.openspec.yaml @@ -0,0 +1,2 @@ +schema: spec-driven +created: 2026-11-17 diff --git a/openspec/changes/title-block-fit-every-field/proposal.md b/openspec/changes/title-block-fit-every-field/proposal.md new file mode 100644 index 00000000..1ff99fd3 --- /dev/null +++ b/openspec/changes/title-block-fit-every-field/proposal.md @@ -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). diff --git a/openspec/changes/title-block-fit-every-field/specs/tools/drawing-package-title-block/spec.md b/openspec/changes/title-block-fit-every-field/specs/tools/drawing-package-title-block/spec.md new file mode 100644 index 00000000..86b28a25 --- /dev/null +++ b/openspec/changes/title-block-fit-every-field/specs/tools/drawing-package-title-block/spec.md @@ -0,0 +1,34 @@ +## 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 diff --git a/openspec/changes/title-block-fit-every-field/tasks.md b/openspec/changes/title-block-fit-every-field/tasks.md new file mode 100644 index 00000000..69bad528 --- /dev/null +++ b/openspec/changes/title-block-fit-every-field/tasks.md @@ -0,0 +1,13 @@ +## 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) + +## 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 diff --git a/openspec/queue.md b/openspec/queue.md index f3ea8842..d7191b4d 100644 --- a/openspec/queue.md +++ b/openspec/queue.md @@ -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` | Built, unit-tested; live check pending (`tests/live/test_live_sw_macro_source.py`) | | 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` | Built, unit-tested; live check pending (`test_live_sw_wave3.py::test_save_body_as_part_writes_the_body_file`) | | 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` | Built, unit-tested; live check pending (`tests/live/test_live_sw_macro_source.py`) | +| 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; live check pending (`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 diff --git a/src/solidworks_mcp/adapters/solidworks/drawing_standard.py b/src/solidworks_mcp/adapters/solidworks/drawing_standard.py index 3872a6c4..bf28725b 100644 --- a/src/solidworks_mcp/adapters/solidworks/drawing_standard.py +++ b/src/solidworks_mcp/adapters/solidworks/drawing_standard.py @@ -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 @@ -317,6 +318,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 @@ -1600,7 +1620,10 @@ def apply(h: float) -> Box | None: } 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. @@ -1625,6 +1648,21 @@ def _fit_title_block(self, s: _Sheet) -> dict[str, dict[str, Any]]: "found": True, **self._fit_field(match[0], right, s.field_height), } + 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) self._attempt(lambda: model.EditRebuild3(), default=None) diff --git a/src/solidworks_mcp/tools/drawing_automation.py b/src/solidworks_mcp/tools/drawing_automation.py index 2f545f05..980cbe32 100644 --- a/src/solidworks_mcp/tools/drawing_automation.py +++ b/src/solidworks_mcp/tools/drawing_automation.py @@ -195,7 +195,7 @@ class GenerateDrawingPackageInput(CompatInput): 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). """ @@ -230,9 +230,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, diff --git a/tests/live/test_live_sw_drawing_package_tools.py b/tests/live/test_live_sw_drawing_package_tools.py index 5120e987..ad78f5d1 100644 --- a/tests/live/test_live_sw_drawing_package_tools.py +++ b/tests/live/test_live_sw_drawing_package_tools.py @@ -278,6 +278,10 @@ async def test_generate_drawing_package_on_a_block(scratch, tmp_path, monkeypatc assert drawing.exists() and pdf.stat().st_size > 0 assert data["overlap_check"]["overlaps_after"] == 0 assert data["title_block"]["drawing number"]["fits"] is True + # Every field the format links to a property is fitted, not just two. + found = {k: v for k, v in data["title_block"].items() if v.get("found")} + assert len(found) > 2, data["title_block"] + assert all(v["fits"] for v in found.values()), found assert "AISI 1020" in shown assert "Package Block" in shown # 13.5 cm^3 of AISI 1020 (7.87 g/cm^3) is about 106 g; the format shows grams. diff --git a/tests/solidworks_mcp/adapters/solidworks/test_drawing_standard_generator.py b/tests/solidworks_mcp/adapters/solidworks/test_drawing_standard_generator.py index a48a149e..ef38864f 100644 --- a/tests/solidworks_mcp/adapters/solidworks/test_drawing_standard_generator.py +++ b/tests/solidworks_mcp/adapters/solidworks/test_drawing_standard_generator.py @@ -1124,3 +1124,67 @@ def test_an_unreadable_prompt_toggle_is_left_alone(files) -> None: app.prompt = "unchanged" adapter._restore_dialog(None) assert app.prompt == "unchanged" + + +# ---- every linked title-block field (title-block-fit-every-field) --------------- + + +def _with_more_fields(*extra: _FormatNote) -> _Drawing: + """The ISO title block, plus more format notes in a row of their own.""" + return _Drawing(format_notes=[*_title_block(), *extra]) + + +@pytest.mark.asyncio +async def test_every_linked_field_is_fitted_and_named(files) -> None: + drawing = _with_more_fields( + _FormatNote( + "Stainless Steel AISI 316L, annealed and pickled, per EN 10088", + '$PRPSHEET:"SW-Material"', + 0.23, + 0.07, + 0.005, + ), + _FormatNote("AB", '$PRP:"DrawnBy"', 0.23, 0.09, 0.0035), + _FormatNote("MATERIAL", "", 0.21, 0.07, 0.002), # a label: not fitted + _FormatNote("again", '$PRPSHEET:"SW-Material"', 0.30, 0.11, 0.005), + _FormatNote("odd", '$PRP:"title"', 0.30, 0.13, 0.002), + ) + + result = await _adapter(files, drawing).create_standard_drawing(files.part) + + title_block = result.data["title_block"] + material = title_block["SW-Material"] + assert material["fits"] is True + assert material["height_mm"] < material["height_mm_before"] == 5.0 + drawn = title_block["drawn by"] + assert drawn["fits"] is True + assert drawn["height_mm"] == drawn["height_mm_before"] == 3.5 + assert drawing.format_notes[7].format.CharHeight == 0.005 # fitted once + assert title_block['$PRP:"title"']["fits"] is True # not over TITLE's entry + assert title_block["title"]["found"] is True + assert set(title_block) == { + "drawing number", + "title", + "SW-Material", + "drawn by", + '$PRP:"title"', + } + + +@pytest.mark.asyncio +async def test_a_linked_field_with_no_box_is_skipped(files) -> None: + class Unmeasured(_FormatNote): + def GetExtent(self): # noqa: N802 + return None + + drawing = _with_more_fields(Unmeasured("x", '$PRP:"Revision"', 0.3, 0.1, 0.004)) + + result = await _adapter(files, drawing).create_standard_drawing(files.part) + + assert "revision" not in result.data["title_block"] + + +def test_linked_property() -> None: + assert std.linked_property('$PRPSHEET:"SW-Material"') == "SW-Material" + assert std.linked_property('$prp:"DrawnBy" and $PRP:"X"') == "DrawnBy" + assert std.linked_property("MATERIAL") is None From 87c55af51a8a7ef5976c9fabb0b2d147b7f0be32 Mon Sep 17 00:00:00 2001 From: Andrew Bartels Date: Tue, 17 Nov 2026 21:33:20 -0800 Subject: [PATCH 2/2] fix: subtitle is the TITLE's second line, not the company (ISO 7200) ISO 7200 treats a subtitle 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 (#158). --- CHANGELOG.md | 4 ++ docs/assets/progress/progress.json | 2 +- docs/assets/progress/progress.svg | 2 +- docs/assets/progress/tool-list-size.md | 6 +-- .../tool-catalog/drawing-automation.md | 2 +- .../tools/drawing-package-title-block/spec.md | 11 +++++ .../title-block-fit-every-field/tasks.md | 5 +++ .../adapters/solidworks/drawing_standard.py | 39 +++++++++++++++-- .../tools/drawing_automation.py | 6 ++- .../test_live_sw_drawing_package_tools.py | 6 ++- .../solidworks/test_drawing_standard.py | 3 +- .../test_drawing_standard_generator.py | 43 +++++++++++++++++++ 12 files changed, 114 insertions(+), 15 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 1deb7735..5ff2d902 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -18,6 +18,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 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 diff --git a/docs/assets/progress/progress.json b/docs/assets/progress/progress.json index 5cb9e2b1..176a0ace 100644 --- a/docs/assets/progress/progress.json +++ b/docs/assets/progress/progress.json @@ -998,7 +998,7 @@ "total": 2838 }, "api": { - "covered": 277, + "covered": 278, "total": 5985 }, "interfaces": [ diff --git a/docs/assets/progress/progress.svg b/docs/assets/progress/progress.svg index 9178b489..19c9e8e7 100644 --- a/docs/assets/progress/progress.svg +++ b/docs/assets/progress/progress.svg @@ -51,5 +51,5 @@ -Whole API: 277 of 5,985 method names (4.6%), counted by a text scan of the adapters. +Whole API: 278 of 5,985 method names (4.6%), counted by a text scan of the adapters. diff --git a/docs/assets/progress/tool-list-size.md b/docs/assets/progress/tool-list-size.md index 73232e79..56f813ec 100644 --- a/docs/assets/progress/tool-list-size.md +++ b/docs/assets/progress/tool-list-size.md @@ -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,142 | 100% | +| `all` | `list` | 140 | 227 KB | 58,160 | 100% | | `core` | `list` | 100 | 151 KB | 38,717 | 67% | -| `drawing` | `list` | 21 | 37 KB | 9,598 | 17% | +| `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,315 | 83% | +| `core,drawing` | `list` | 121 | 189 KB | 48,333 | 83% | | `all` | `search` | 4 | 4 KB | 908 | 2% | | `core` | `search` | 4 | 4 KB | 908 | 2% | diff --git a/docs/user-guide/tool-catalog/drawing-automation.md b/docs/user-guide/tool-catalog/drawing-automation.md index 73fcd2e0..3597de71 100644 --- a/docs/user-guide/tool-catalog/drawing-automation.md +++ b/docs/user-guide/tool-catalog/drawing-automation.md @@ -109,7 +109,7 @@ Every title-block field the sheet format fills from a property (DWG NO., TITLE, | `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 | diff --git a/openspec/changes/title-block-fit-every-field/specs/tools/drawing-package-title-block/spec.md b/openspec/changes/title-block-fit-every-field/specs/tools/drawing-package-title-block/spec.md index 86b28a25..823a3977 100644 --- a/openspec/changes/title-block-fit-every-field/specs/tools/drawing-package-title-block/spec.md +++ b/openspec/changes/title-block-fit-every-field/specs/tools/drawing-package-title-block/spec.md @@ -32,3 +32,14 @@ TITLE `title`; the drawing's own fields SHALL use the names - **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 diff --git a/openspec/changes/title-block-fit-every-field/tasks.md b/openspec/changes/title-block-fit-every-field/tasks.md index 69bad528..5015d330 100644 --- a/openspec/changes/title-block-fit-every-field/tasks.md +++ b/openspec/changes/title-block-fit-every-field/tasks.md @@ -2,6 +2,11 @@ - [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 diff --git a/src/solidworks_mcp/adapters/solidworks/drawing_standard.py b/src/solidworks_mcp/adapters/solidworks/drawing_standard.py index bf28725b..274a49a3 100644 --- a/src/solidworks_mcp/adapters/solidworks/drawing_standard.py +++ b/src/solidworks_mcp/adapters/solidworks/drawing_standard.py @@ -264,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). @@ -281,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} @@ -464,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 @@ -487,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: @@ -1619,6 +1629,23 @@ 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 sheet format's title-block fields to their boxes. @@ -1642,11 +1669,14 @@ 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: @@ -1789,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 ``-Rev-01``. author: DRAWN name. @@ -1915,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 diff --git a/src/solidworks_mcp/tools/drawing_automation.py b/src/solidworks_mcp/tools/drawing_automation.py index 980cbe32..6877e963 100644 --- a/src/solidworks_mcp/tools/drawing_automation.py +++ b/src/solidworks_mcp/tools/drawing_automation.py @@ -187,7 +187,7 @@ 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. @@ -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, diff --git a/tests/live/test_live_sw_drawing_package_tools.py b/tests/live/test_live_sw_drawing_package_tools.py index ad78f5d1..7a6a113a 100644 --- a/tests/live/test_live_sw_drawing_package_tools.py +++ b/tests/live/test_live_sw_drawing_package_tools.py @@ -250,6 +250,7 @@ async def test_generate_drawing_package_on_a_block(scratch, tmp_path, monkeypatc "model_path": part, "output_dir": str(out), "title": "Package Block", + "subtitle": "Base support", "drawing_number": "PB-01", "author": "Live test", } @@ -283,7 +284,10 @@ async def test_generate_drawing_package_on_a_block(scratch, tmp_path, monkeypatc assert len(found) > 2, data["title_block"] assert all(v["fits"] for v in found.values()), found assert "AISI 1020" in shown - assert "Package Block" in shown + # ISO 7200: the subtitle is the TITLE's second line, not the company. + title = next(t for t in shown if t.startswith("Package Block")) + assert title.splitlines() == ["Package Block", "Base support"], title + assert sum("Base support" in t for t in shown) == 1, shown # 13.5 cm^3 of AISI 1020 (7.87 g/cm^3) is about 106 g; the format shows grams. weight = next(t for t in shown if t.startswith("WEIGHT:")) assert 100 < float(weight.split(":")[1]) < 112, weight diff --git a/tests/solidworks_mcp/adapters/solidworks/test_drawing_standard.py b/tests/solidworks_mcp/adapters/solidworks/test_drawing_standard.py index 9fe9c77a..4471f39b 100644 --- a/tests/solidworks_mcp/adapters/solidworks/test_drawing_standard.py +++ b/tests/solidworks_mcp/adapters/solidworks/test_drawing_standard.py @@ -100,8 +100,7 @@ def test_title_block_properties(self) -> None: "DrawnBy": "saiq", "DrawnDate": "17 Oct 2026", "Revision": "A", - "COMPANYNAME": "Part drawing", - } + } # the subtitle is not the company (ISO 7200's legal owner) def test_empty_drawing_properties_are_left_out(self) -> None: _, drawing = std.title_block_properties( diff --git a/tests/solidworks_mcp/adapters/solidworks/test_drawing_standard_generator.py b/tests/solidworks_mcp/adapters/solidworks/test_drawing_standard_generator.py index ef38864f..6327b8f8 100644 --- a/tests/solidworks_mcp/adapters/solidworks/test_drawing_standard_generator.py +++ b/tests/solidworks_mcp/adapters/solidworks/test_drawing_standard_generator.py @@ -199,6 +199,10 @@ def SetTextFormat(self, _kind, text_format): # noqa: N802 def GetNext(self): # noqa: N802 return self.next + def SetText(self, text): # noqa: N802 + self.text = text.replace(self.PropertyLinkedText, "Mounting Plate") + return True + def _title_block(drawing_number: str = "MOUNTING-PLATE-RevA-01") -> list[_FormatNote]: """The ISO title block's notes: DWG NO. runs into the size box at 7 mm.""" @@ -1188,3 +1192,42 @@ def test_linked_property() -> None: assert std.linked_property('$PRPSHEET:"SW-Material"') == "SW-Material" assert std.linked_property('$prp:"DrawnBy" and $PRP:"X"') == "DrawnBy" assert std.linked_property("MATERIAL") is None + + +# ---- the subtitle: ISO 7200's supplementary title, under the TITLE --------------- + + +@pytest.mark.asyncio +@pytest.mark.parametrize(("cap_mm", "height_mm"), [(None, 3.0), (2, 2.0)]) +async def test_a_subtitle_is_the_titles_second_line(files, cap_mm, height_mm) -> None: + drawing = _Drawing() + title_note = drawing.format_notes[3] + + result = await _adapter(files, drawing).create_standard_drawing( + files.part, subtitle=" Base support ", title_block_text_height_mm=cap_mm + ) + + assert title_note.text == "Mounting Plate" + "\r\n" + "Base support" + title = result.data["title_block"]["title"] + assert title["height_mm"] <= height_mm # 60% of the format's 5 mm, or the cap + assert title["fits"] is True + + +@pytest.mark.asyncio +async def test_no_subtitle_leaves_the_title_one_line(files) -> None: + drawing = _Drawing() + + await _adapter(files, drawing).create_standard_drawing(files.part, subtitle=" ") + + assert drawing.format_notes[3].text == "Mounting Plate" + + +def test_a_title_with_no_readable_height_keeps_the_callers_cap(files) -> None: + class Unreadable(_FormatNote): + def GetTextFormat(self): # noqa: N802 + raise RuntimeError("no format") + + note = Unreadable("T", '$PRPSHEET:"Description"', 0.23, 0.045, 0.005) + adapter = _adapter(files) + assert adapter._add_subtitle(note, note.PropertyLinkedText, "Sub", 0.002) == 0.002 + assert adapter._add_subtitle(note, note.PropertyLinkedText, "Sub", None) is None