fix(task-24a): apply_standard decides each unit write on a read taken after the dimension style switch

f7528b2 moved the five unit reads of apply_standard ahead of the style
stage so a refused read is a refusal with nothing written -- and then
decided the writes on those reads. Making a dimension style current
restores every DIM* variable from the style (ezdxf: _sync_header_to_dimstyle
on dimstyle_set_current; AutoCAD: ActiveDimStyle), so on a drawing whose
ISO-25/ANSI already carried another scale the gate read (1.0) equalled
the target, the DIMSCALE write was skipped and the drawing ended at the
style's scale while the report said `changed: {}` -- against the spec's
"LTSCALE 1, DIMSCALE 1" and the tool docstring. The pre-f7528b2 loop ran
after the switch and got this right; this is a regression of f7528b2.

The gate read stays (readable before anything is written); each variable
is read again after the style stage and the write is decided on that
value, so `changed` says what the write moved.

Measured on the running AutoCAD 2026 (25.1s, 2026-09-22, scratch
Documents.Add(), Close(False), real ComBackend after connect()):

    ISO-25 modified to DIMSCALE 2.0 (dimstyle_modify -> {'DIMSCALE': [1.0, 2.0]}),
    Annotative current, doc.GetVariable('DIMSCALE') -> 1.0
    before: apply_standard(iso, layers=False)
            -> {'changed': {}, 'applied': True}; ActiveDimStyle ISO-25;
               doc.GetVariable('DIMSCALE') -> 2.0
    after:  -> {'changed': {'DIMSCALE': [2.0, 1.0]}, 'applied': True};
               ActiveDimStyle ISO-25; doc.GetVariable('DIMSCALE') -> 1.0

ezdxf, same setup (dimstyle_create ISO-25 {DIMSCALE: 2.0}, Standard
current): before `{'INSUNITS': [6, 4]}` and DIMSCALE 2.0 afterwards;
after `{'INSUNITS': [6, 4], 'DIMSCALE': [2.0, 1.0]}` and DIMSCALE 1.0.

Tests: one regression per engine (both fail on the f7528b2 apply.py);
test_com_apply_standard_creates_both_styles_and_sets_units now pins the
gate reads first *and* the re-read-then-write sequence after CopyFrom,
instead of enshrining the stale-read order.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01FKFStjEFzpGyLq5bMpWxTd
This commit is contained in:
Umut CAN
2026-09-22 12:37:33 +03:00
co-authored by Claude Opus 5
parent f7528b2fa5
commit d072df9fd4
2 changed files with 86 additions and 12 deletions
+13 -5
View File
@@ -68,17 +68,23 @@ async def apply_standard(
written. (The units loop used to run after both styles; on the live
engine its INSUNITS read went through a member the ActiveX Application
does not have, so the call failed with ISO-25 and ISOCP already created
and current.)
and current.) That first read is only the gate: making a dimension style
current restores every DIM* variable from the style (ezdxf syncs the
header; AutoCAD 2026 measured ``ActiveDimStyle = ISO-25`` with a style
DIMSCALE of 2.0 moving the document's DIMSCALE 1.0 -> 2.0), so each
variable is read again *after* the style switch and the write is decided
on that value. Deciding on the gate read skipped the DIMSCALE write
whenever a pre-existing ISO-25/ANSI carried another scale, and reported
``changed: {}`` on a drawing left at the style's scale.
"""
key, row = resolve_standard(standard)
if not isinstance(layers, bool) or not isinstance(units, bool):
raise TypeError("layers and units must be booleans")
current: dict[str, Any] = {}
if units:
if units: # the refusal gate: every variable readable before anything is written
for var, _value in STANDARD_SYSVARS:
try:
current[var] = await backend.system_get_variable(var)
await backend.system_get_variable(var)
except Exception as exc:
raise RuntimeError(
f"apply_standard: could not read {var} before writing "
@@ -104,7 +110,9 @@ async def apply_standard(
changed: dict[str, list] = {}
if units:
for var, value in STANDARD_SYSVARS:
old = current[var]
# Re-read after the style switch: the gate value is stale for
# DIM* once another dimension style has been made current.
old = await backend.system_get_variable(var)
if _same(old, value):
continue
await backend.system_set_variable(var, value)