Repository navigation
CAD: choose the AutoCAD version to write DWG and DXF in (#489) - #497
Conversation
A preset that writes DWG or DXF has an AutoCAD version: 2018 (default), 2013, 2010, 2007, 2004, 2000 or the source's own (older than 2000 becomes 2000), and DWG -> DWG / DXF -> DXF can change the version. - ACadSharp 3.8 can't write a 2007 DWG: chosen, it is 2004 (AutoCAD 2007 opens it); kept from a 2007 source, 2010. - Before 2007 text is in $DWGCODEPAGE. CadCodePages picks the code page that holds most of the text (the drawing's own on a tie; Korean for Hangul, Japanese for Kana, Big5 then GBK for Chinese, East Asian pages only for East Asian text) and writes anything it can't hold as \U+XXXX. Korean goes out as ANSI_949 like AutoCAD writes it (ACadSharp needs KCS5601 to encode it, so the DXF header is renamed after writing). - Objects the version doesn't have are left out with a note: tables and arc dimensions before 2004, multileaders and PDF underlays before 2007, meshes before 2010. - SVG -> DXF honours the version too.
ne.json and th.json: kept main's OCR strings next to the CAD notice.
KnifeLemon
left a comment
There was a problem hiding this comment.
Thanks @cre8ive-marketing, this covers both points from #489 well, and finding the ANSI_949 / KCS5601 quirk was a good catch. I merged it with current main and ran dotnet format --verify-no-changes, the build, the CAD / DXF / DWG / SVG engine tests (72 passed), Core (510) and the preset editor and localization App tests (115). All 14 language files have the 5 new keys.
I also checked the round trip with a local test, not committed. It saved drawings as 2000, 2004 and 2018, in both DXF and DWG, and read them back with CadFile.Read. The drawings had TEXT, MTEXT, an attribute definition and attributes in Korean, simplified and traditional Chinese, Japanese and Russian, each starting from ANSI_1252:
- Every text came back unchanged.
- The DXF headers said
ANSI_949,ANSI_936,ANSI_950,ANSI_932orANSI_1251as expected, and Chinese in a Korean drawing went out as\U+XXXX. - 2007 DWG → 2004 and "Same as the source" for a 2007 DWG → 2010 both match what we agreed.
One thing needs fixing before it goes in:
1. Names aren't counted when the code page is picked. A drawing with a layer named 벽체 and only English text, saved as 2000 or 2004, gets ANSI_1252, and the layer comes back as ?? in both DXF and DWG. Korean layer names with English labels are very common in Korean drawings. Please count the names of layers, blocks, text styles, dimension styles, linetypes and layouts, and attribute tags, in CadCodePages.Choose. If you can, escape names the chosen page can't hold the same way as text. A test with a Korean layer and ASCII-only text would cover it.
Smaller ones:
- A character outside the BMP (an emoji) comes back as
??, one?for each half of the surrogate pair. One?per character would be tidier. - The DWG header gets code page index 25 (
KSC5601) for Korean and 31 (GB2312) for simplified Chinese, while the DXF header saysANSI_949. Korean and Chinese AutoCAD write 40 / 39 / 41 (ANSI_949/ANSI_936/ANSI_950). ACadSharp reads both back the same way. If it's easy to write theANSI_index, DWG and DXF would agree. This is optional, since neither of us can open the files in AutoCAD 2000/2004. - Tables are kept in 2004, but the text in their cells doesn't go through the code page choice or the escapes. This is optional too, and a note in
docs/ENGINES.mdis fine.
The CI build failure is ToolbarPaletteModelTests.Deleted_profile_loses_its_cache_entry, which this PR doesn't touch. It should pass on a re-run after merging main. You're right that no settings migration is needed. We'll adjust the Korean strings to the app's usual tone ourselves, so leave those as they are.
To get this into the next release, we'll push the remaining changes to your branch ourselves today if you haven't by then. Have a look at the commits when they land.
To get this into the next release, we'll push the remaining changes to your branch ourselves today (maintainer edits are on). Have a look at the commits when they land, and tell us if anything looks off.
… review) 1. Layer, block, text style, dimension style, linetype and layout names and attribute tags count when the code page is picked, and are escaped like text: a Korean layer in a drawing with only English text gets ANSI_949 instead of coming back as "??". Tests in 2000 and 2004, DXF and DWG, and a mixed-script layer name escaped as \U+XXXX. 2. A character outside the BMP is one "?", not one per surrogate half. 3. ENGINES.md: text in table cells isn't escaped; the DWG header keeps ACadSharp's code page index (KSC5601 / GB2312).
…ls, the DWG code page index
|
Thanks @KnifeLemon, and for the round-trip check across scripts. Done in b75684c and 0edb87b:
All 61 CAD tests pass and |
The 14 i18n files take both sides: the CAD keys and main's replace-the-original keys. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
On macos-15-intel the App tests alone take about 40 minutes (40 m 23 s on main's run for KnifeLemon#496), so a slow runner went past the 60-minute limit and was cancelled (KnifeLemon#497 twice, KnifeLemon#500 once). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Closes #489. This follows the plan agreed there and covers both points from your ACadSharp 3.8.0 check.
What it does
CAD presets get an AutoCAD version choice, in a new "CAD drawing" card in the preset editor. It shows when the target is DWG or DXF. The options are:
DWG → DWG and DXF → DXF are now routes too, so a preset can just change the version. SVG → DXF (tracing) honours the choice as well.
Version names stay "AutoCAD 2018" and so on in every language. The settings schema doesn't change:
CadOptions.Versionis a new enum that defaults to 2018, read withLenientEnumJsonConverter.Your two points
CadCodePagespicks the code page from the text when writing 2004 or older:ANSI_949, Kana givesANSI_932, and Chinese characters giveANSI_950beforeANSI_936. That way traditional text, which both hold, gets Big5, and simplified text, which Big5 lacks, gets GBK.\U+XXXX, so mixed scripts survive. Characters outside the BMP become?, because\U+takes four hex digits only.ANSI_949. With that header it writes the DXF text as UTF-8 and the DWG as 1252. It does knowKCS5601, which encodes CP949 correctly. So Korean is written withKCS5601, and the DXF header is then renamed toANSI_949, the name AutoCAD writes. This is the reverse of whatOpenDxfalready does on reading.Objects the version doesn't have
These are left out with a note (
notice.cad_newer_left_out), and the file is still written:ACadSharp writes all of them into any version without complaining, but older AutoCAD can't read them.
Tests (
CadVersionTests, and an editor test inRenderTests)\U+decoded)ANSI_1252, as you described$DWGCODEPAGE ANSI_949, the Korean text in CP949 bytes, and这written as\U+8FD9.docs/ENGINES.md(Writing) describes all of this.dotnet format --verify-no-changesis clean. Fulldotnet test: Platform 48, Core 504, CLI 27, Setup 149, Engines 1629 and App 904 pass, none fail (before merging currentmain, which brought in Recognize text in scans and pictures with Tesseract (OCR, #288) #429; after the merge, the CAD, preset editor and localization tests pass again).Not checked: opening the files in real AutoCAD 2000/2004/2007. I don't have those versions, so the round trips are through ACadSharp's own reader.