Skip to content
Closed
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
7 changes: 2 additions & 5 deletions crates/dwg/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1028,14 +1028,11 @@ mod native {
/// dictionary, with the variables it keeps there, when the drawing has none (#1813).
/// Vectric Aspire 10.5 reads a 2004 (AC1018) DWG without it as empty ("No data was imported
/// from the DXF / DWG file"), though it reads the same drawing as DXF — which has no such
/// dictionary either, as CADCraft's and ezdxf's writers don't make one. AutoCAD's AC1032 DWGs
/// read there without it, so newer output is left as it was, and a dictionary the drawing
/// dictionary either, as CADCraft's and ezdxf's writers don't make one. ZWCAD 2025's AUDIT reports
/// an AC1032 DWG without it as an error, so every version gets it. A dictionary the drawing
/// does have keeps its own entries and values.
fn add_variable_dictionary(doc: &mut acadrust::CadDocument) {
use acadrust::objects::{Dictionary, DictionaryVariable, ObjectType};
if doc.version >= acadrust::DxfVersion::AC1032 {
return;
}
let root_handle = doc.header.named_objects_dict_handle;
match doc.objects.get(&root_handle) {
Some(ObjectType::Dictionary(root)) => {
Expand Down
16 changes: 9 additions & 7 deletions crates/io/tests/dwg_required_dictionaries.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
//! #1813: AutoCAD always writes an `AcDbVariableDictionary` in the named object dictionary;
//! ezdxf, and CADCraft's own DXF writer, do not. Vectric Aspire 10.5 reads an AC1018 DWG without
//! it as empty ("No data was imported..."), though it reads the same drawing as DXF (and as an
//! AC1032 DWG) fine. The DWG bridge adds the dictionary AutoCAD writes, with its usual variables,
//! it as empty ("No data was imported..."), though it reads the same drawing as DXF fine,
//! and ZWCAD 2025's AUDIT flags an AC1032 DWG without it. The DWG bridge adds the dictionary AutoCAD writes, with its usual variables,
//! when the DXF has none.
#![cfg(not(target_arch = "wasm32"))]

Expand Down Expand Up @@ -114,16 +114,18 @@ fn impossible_header_values_fall_back_to_the_defaults() {
assert_eq!(value(&vars, "HIDETEXT"), Some("1"), "HIDETEXT in {vars:?}");
}

/// The AC1032 (AutoCAD 2018) path is deliberately unchanged: those DWGs read in Vectric Aspire
/// without the dictionary, so no dictionary is injected and the existing output stays as it was.
/// An AC1032 (AutoCAD 2018) DWG gets the dictionary too: ZWCAD 2025's AUDIT reports one without
/// it as an error ("AcDbVariableDictionary Dictionary Invalid class type of (0)").
#[test]
fn an_ac1032_dwg_stays_as_it_was() {
// 2018 DWGs read fine in Aspire without the dictionary, so the latest format is unchanged.
fn an_ac1032_dwg_gets_the_variable_dictionary_too() {
let d = rectangle();
let dwg = write_with(&d, "rect.dwg", &SaveOptions { version: Some(Version::R2018), binary: false }).expect("write the DWG");
assert!(dwg.starts_with(b"AC1032"));
let doc = read_dwg(&dwg);
assert_eq!(variable_dictionary(&doc), None, "no dictionary is added to a 2018 DWG");
let vars = variable_dictionary(&doc).expect("AC1032 DWG: the named object dictionary has an AcDbVariableDictionary");
assert_eq!(value(&vars, "CANNOSCALE"), Some("1:1"), "{vars:?}");
let back = cadcraft_io::read(&dwg, "rect.dwg").expect("CADCraft reads its own 2018 DWG");
assert_eq!(back.model.len(), 1);
}

/// A drawing that already has the dictionary must keep its own entries and values: conversion
Expand Down
Loading