Add $INSUNITS header variable to DXF export

The DXF exporter was missing the $INSUNITS header variable, which tells
CAD software what physical units the drawing coordinates represent. Without
it, other programs have no reliable way to determine the coordinate scale.

Add $INSUNITS to the HEADER section alongside the existing $MEASUREMENT
variable. When exporting in millimeters, $INSUNITS is set to 4; when
exporting in inches, it is set to 1.

Fixes https://gitlab.com/kicad/code/kicad/-/issues/23181
This commit is contained in:
Seth Hillbrand
2026-02-23 12:14:49 -08:00
parent 25941bc77a
commit c0a6a139cf
2 changed files with 18 additions and 1 deletions
+7 -1
View File
@@ -701,12 +701,14 @@ void DXF_PLOTTER::SetUnits( DXF_UNITS aUnit )
case DXF_UNITS::MM:
m_unitScalingFactor = 0.00254;
m_measurementDirective = 1;
m_insUnits = 4;
break;
case DXF_UNITS::INCH:
default:
m_unitScalingFactor = 0.0001;
m_measurementDirective = 0;
m_insUnits = 1;
}
}
@@ -779,6 +781,10 @@ bool DXF_PLOTTER::StartPlot( const wxString& aPageNumber )
"$MEASUREMENT\n"
" 70\n"
"{}\n"
" 9\n"
"$INSUNITS\n"
" 70\n"
"{}\n"
" 0\n"
"ENDSEC\n"
" 0\n"
@@ -873,7 +879,7 @@ bool DXF_PLOTTER::StartPlot( const wxString& aPageNumber )
"-0.2\n"
" 0\n"
"ENDTAB\n",
GetMeasurementDirective() );
GetMeasurementDirective(), GetInsUnits() );
// Text styles table
// Defines 4 text styles, one for each bold/italic combination