Skip to content

-INSERT of a drawing file converts its INSUNITS - #3482

Merged
HakanSeven12 merged 2 commits into
HakanSeven12:mainfrom
jespinolao:fix/insert-file-keeps-its-units
Nov 23, 2026
Merged

HakanSeven12 merged 2 commits into
HakanSeven12:mainfrom
jespinolao:fix/insert-file-keeps-its-units

Conversation

@jespinolao

Copy link
Copy Markdown
Contributor

How it shows up

Fixes #3474. A drawing named at -INSERT's block prompt comes in at scale 1 whatever its INSUNITS: a metres drawing inserted into a millimetre drawing is 1000 times too small. An XREF of the same file is scaled.

Synthetic drawings, each a 10-unit line: metres.dwg (INSUNITS 6), feet.dwg (2), inches.dwg (1), millimetres.dwg (4), inserted into a new drawing with INSUNITS 4 by -INSERT <file> 0,0 1 1 0.

Cause

A new block reference is already scaled by its block's units against the drawing's INSUNITS, in one place: commit_entity_handle_with_policies (src/app/properties.rs) uses insert_unit_scale(host, record.units). A block brought in from a file by import_document_block (src/app/update/dialog.rs) is defined from the file's model space, but its block record keeps units 0, unitless, so that factor is 1. Saved to DXF, the four blocks have 70 = 0 in their BLOCK_RECORD.

The change

import_document_block gives the block record the file's header.insertion_units once the block is defined. Nothing else changes: the scale is then applied where it already is for any block with units. A unitless file stays unitless, and a drawing with INSUNITS 0 still inserts at scale 1, since insert_unit_scale returns no factor when either side is unitless.

import_document_block is reached from -INSERT with a file name, the Blocks palette (insert of a drawing, and Redefine from a drawing), and a table cell's block from a file. The first two place their reference through the same commit, so they scale too. A table cell's block is not placed as a block reference, and the table code does not read block units (by reading the code; not run).

Measured

Release builds, Windows 11. main is 8e5f39f with the gpu-allocator line of 35d5fc5; the branch now sits on c206c53, whose changes since are in tests, the release workflow, Cargo.lock and viewport selection. The same script on both builds.

-INSERT into a drawing with INSUNITS 4 expected main This PR
metres.dwg (6) 1000 1 1000
feet.dwg (2) 304.8 1 304.8
inches.dwg (1) 25.4 1 25.4
millimetres.dwg (4) 1 1 1
a unitless drawing (0) 1 1 1

Then, on the reference of metres.dwg, each step on both builds. Every result is the main one times 1000, and nothing is converted twice:

Step main: scale / extent This PR: scale / extent
-INSERT metres.dwg 1 / 10 1000 / 10,000
COPY copy 1 / 10 copy 1000 / 10,000
MIRROR, keeping the source 1, −1 / 10 1000, −1000 / 10,000
COPYCLIP, PASTECLIP pasted 1 / 10 pasted 1000 / 10,000
-INSERT metres (by name) 1 / 10 1000 / 10,000
ROTATE 90 1 / 10 1000 / 10,000
SCALE 2 2 / 20 2000 / 20,000
EXPLODE of the copy a line 10 long a line 10,000 long
SAVE, then OPEN as before saving as before saving
main This PR
main: the 10 m line inserted 10 mm long, at the frame's corner this PR: the 10 m line fills the 10,000 mm frame

Tests

  • insert_of_a_drawing_file_converts_its_units (src/app/commands/blocks.rs): writes the five drawings and runs -INSERT <file> 0,0 1 1 0 into a millimetre drawing for each. Fails on the first commit: metres drawing inserted into a millimetre drawing at scale 1, expected 1000; all scales: [("metres", Some(1.0)), ("feet", Some(1.0)), ("inches", Some(1.0)), ("millimetres", Some(1.0)), ("unitless", Some(1.0))].
  • The test is the first commit; the change is the second.
  • cargo test --lib app::commands::blocks::tests app::update::dialog::tests: 58 passed. On c206c53, the new test with app::update::dialog::tests: 21 passed.
  • cargo test --workspace --no-fail-fast: 7,756 passed, 1 failed, 49 ignored. The failure, app::control::spellcheck::tests::speller_survives_com_unload_reload_cycles, fails the same way on main on this machine.
  • cargo check --target wasm32-unknown-unknown --lib passes.

Limits

  • While a block with units is being placed, its preview is drawn at the typed scale without the unit factor, and the reference lands at the converted size. That is how main already places any block with units (a block with units 6 inserted by name into a millimetre drawing shows a 10-unit preview and lands at 1000); a drawing file now does the same. Not changed here.
  • The Blocks palette was checked by reading the code, not run.
  • INSUNITSDEFSOURCE and INSUNITSDEFTARGET are not read, as before: a unitless side means no conversion.

OCS main at c206c53, Windows 11.

🤖 Generated with Claude Code

jespinolao and others added 2 commits November 22, 2026 19:39
A metres drawing named at -INSERT's block prompt in a millimetre
drawing must come in at scale 1000, feet at 304.8, inches at 25.4, as
an XREF of the same file does. All come in at 1 (HakanSeven12#3474).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
-INSERT of a drawing file, the Blocks palette and Redefine from a file
define the block from the file's model space but left the block record
unitless, so a new reference was not scaled against the drawing's
INSUNITS and a metres drawing came into a millimetre one 1000 times too
small (HakanSeven12#3474). The record now takes the file's INSUNITS; references
then scale the way they already do for any block with units, and as an
XREF of the same file does. A unitless file stays unitless.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@HakanSeven12
HakanSeven12 merged commit e99cccb into HakanSeven12:main Nov 23, 2026
7 of 8 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

-INSERT of a drawing file ignores its INSUNITS (no unit conversion), AutoCAD scales it

2 participants