diff --git a/CHANGELOG.md b/CHANGELOG.md index adbfeb3..914fc7c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -15,6 +15,10 @@ _Next: closed-loop refiner (critique→repair→re-critique with transaction-sta matching the project name, so hatchling could not infer which files to ship. `pyproject.toml` now declares the wheel file selection explicitly (`server.py`, `config.py`, `security.py`, `backends/`, `engineering/`). (#2) +- **`dimension_linear` on the COM backend** — always crashed with + `.AddDimLinear`: the AutoCAD ActiveX API has no `AddDimLinear` + method. Linear dimensions are now created via `AddDimRotated` (identical + argument order), with a mocked regression test. (#3) ## [1.2.0] — 2026-07-07 diff --git a/backends/com_backend.py b/backends/com_backend.py index 21eecbc..3a1e2f3 100644 --- a/backends/com_backend.py +++ b/backends/com_backend.py @@ -824,7 +824,9 @@ class ComBackend(AutoCADBackend): ) -> EntityInfo: def _sync(): mspace = _msp() - dim = mspace.AddDimLinear( + # The ActiveX API has no AddDimLinear — rotated linear dims are + # created with AddDimRotated (GH issue #3). + dim = mspace.AddDimRotated( _apoint(x1, y1), _apoint(x2, y2), _apoint(dim_x, dim_y), deg2rad(rotation), ) diff --git a/tests/test_com_backend.py b/tests/test_com_backend.py index 916bbc9..73d1829 100644 --- a/tests/test_com_backend.py +++ b/tests/test_com_backend.py @@ -211,6 +211,42 @@ def test_safe_send_command_new_handle_detection(): assert set(result) == {"1C", "1D"} +# --------------------------------------------------------------------------- +# dimension_linear — must use AddDimRotated (GH issue #3) +# --------------------------------------------------------------------------- + + +@pytest.mark.asyncio +async def test_dimension_linear_uses_add_dim_rotated(): + """Regression for GH issue #3: the AutoCAD ActiveX API has no AddDimLinear + method — calling it raised ``.AddDimLinear``. Linear dimensions + must go through AddDimRotated.""" + backend = ComBackend() + + async def _run_inline(func, *args, **kwargs): + return func(*args, **kwargs) + + backend._run = _run_inline # bypass the COM executor thread + + mspace = MagicMock() + with ( + patch("backends.com_backend._msp", return_value=mspace), + patch("backends.com_backend._apoint", side_effect=lambda *a: tuple(float(v) for v in a)), + patch("backends.com_backend._regen"), + patch("backends.com_backend._apply_dim_tolerance"), + patch("backends.com_backend._entity_info", side_effect=lambda e: e), + ): + await backend.dimension_linear(0, 0, 100, 0, 50, 20, rotation=0.0) + + mspace.AddDimRotated.assert_called_once() + mspace.AddDimLinear.assert_not_called() + args = mspace.AddDimRotated.call_args[0] + assert args[0] == (0.0, 0.0) # ext line 1 origin + assert args[1] == (100.0, 0.0) # ext line 2 origin + assert args[2] == (50.0, 20.0) # dim line location + assert args[3] == pytest.approx(0.0) # rotation in radians + + # --------------------------------------------------------------------------- # Live integration — skipped unless AutoCAD is reachable # ---------------------------------------------------------------------------