Two posts in the last week on r/SolidWorks surface the same class of bug: DXFs that look fine in SolidWorks land corrupted downstream. One user watched bend lines lean off-axis on a small flange until they dropped the end point merging tolerance from 1 to 0.1. Another spent a week re-ticking the entity checkboxes on every export because SolidWorks does not remember them. Both problems come from defaults that SolidWorks ships and almost nobody documents — buried in a bitmask you only see if you touch the API.
Here is what every flag actually does, why the tolerance default is wrong for most sheet metal, and how to pin the right settings so you stop paying the tax every export.
The bitmask nobody shows you
When you click File → Save As → DXF, SolidWorks walks you through a wizard. When a macro, add-in, or IPartDoc::ExportToDWG2 call does the same thing, it passes a single integer bitmask called SheetMetalOptions_e (older docs call it swExportFlatPatternOption_e). The wizard checkboxes correspond one-to-one to bits in that integer. The wizard defaults are not the defaults the API uses — and the API defaults are not the defaults you want.
Here is the full bitmask, decompiled from SolidWorks.Interop.swconst.dll and cross-checked against the 2022 and 2025 API help:
| Bit | Value | Flag | Controls |
|---|---|---|---|
| 0 | 1 | ExportFlatPatternGeometry | Base outline of the flat pattern. Without this you get an empty file. |
| 1 | 2 | IncludeHiddenEdges | Hidden/tangent edges. Almost always wrong for laser — creates entities for features the laser cannot see. |
| 2 | 4 | ExportBendLines | Bend-up and bend-down centerlines. Required if the press brake reads bend data from the DXF. |
| 3 | 8 | IncludeSketches | User sketches on the flat pattern. Useful for etch marks, punch locations, alignment crosses. |
| 4 | 16 | MergeCoplanarFaces | Merges coplanar split polylines into one. Reduces entity count. |
| 5 | 32 | ExportLibraryFeatures | Library-feature marks (common for reusable tab/slot patterns). |
| 6 | 64 | ExportFormingTools | Forming-tool footprints (louvers, knockouts, embosses). |
| 11 | 2048 | ExportBoundingBox | Sheet bounding rectangle, used by material-cost estimators and nesters. |
Combine them with | (OR). Common presets:
5= geometry + bend lines. Minimal laser-ready output.13= geometry + bend lines + sketches. Laser with etch marks.21= geometry + bend lines + merge coplanar. Clean laser output.1109=5 | 32 | 64 | 2048= geometry + bend lines + library features + forming tools + bounding box. Full sheet-metal nesting package.
If you call ExportToDWG2 with vSheetMetalOptions = 0, you get an empty file. SolidWorks will happily export it without an error.
The end point merging tolerance footgun
The DXF/DWG export options dialog (Tools → Options → Export → DXF/DWG) has an “Enable Merging” group with a max gap field. The SolidWorks default is 1.0 in the active document unit. On a part authored in inches, that is one inch. On a part with a 0.5" tab, the tolerance is twice the size of the feature.
Here is what happens internally when that tolerance fires. SolidWorks projects the 3D flat pattern down to 2D, which produces a list of entities (lines, arcs, splines) with endpoint coordinates carrying small numerical noise — on the order of 1e-6 units from the kernel’s tessellation and B-Rep to polyline conversion. The export pipeline runs a proximity cluster pass: every pair of endpoints whose Euclidean distance is below the tolerance is collapsed into a single averaged vertex, and every entity referencing either original endpoint is rewired to the merged point.
When the tolerance is 1 inch and your tab is 0.5 inches wide, the cluster pass merges opposite corners of the tab. Bend lines that crossed the tab now snap to a merged vertex that did not exist in the original geometry. Visually, the bend line leans; numerically, it is perfectly straight but attached to the wrong point.
The correct tolerance is smaller than your smallest real feature but larger than the projection noise. For most sheet metal:
- Metric:
0.025 mm(one tenth of typical cutter kerf). - Imperial:
0.001 in(one thousandth — below the precision any laser can achieve).
There is a separate regional-settings bug worth knowing about: if you type 0,001 with a European comma on a US-locale SolidWorks build, the dialog silently reverts to 0 when reopened. Always reopen the dialog after setting it to confirm the value stuck.
This is the same class of problem described in why your DXF flat pattern dimensions do not match the folded part — small, invisible numerical choices that appear correct in preview and fail at the shop floor.
Layer mapping is persistent — entity selection is not
SolidWorks persists two things related to DXF export, and only two:
- The active layer mapping file, via the user preference
swDxfMappingFileIndex(integer, index intoswDxfMappingFilesstring list). - The export version and scale, via
swDxfVersionandswDxfOutputScaleFactor.
That is it. The entity checkboxes you tick (IncludeSketches, ExportBendLines, IncludeHiddenEdges, ExportBoundingBox) are not persisted by SolidWorks between exports. The dialog resets them to internal defaults every time.
The user preference keys live in the Windows registry under HKCU\Software\SolidWorks\SolidWorks <version>\Export Options\DXF. The registry also stores the mapping file list, which is why it survives restarts. Entity selection never lands in the registry, which is why it never survives.
If you want a mapping file to be active for every export from a macro, pin it like this:
var mapFiles = (string[])swApp.GetUserPreferenceStringListValue(
(int)swUserPreferenceStringListValue_e.swDxfMappingFiles);
int idx = Array.FindIndex(mapFiles, p =>
p.EndsWith("laser-cut.txt", StringComparison.OrdinalIgnoreCase));
if (idx < 0)
throw new InvalidOperationException("Mapping file not registered");
swApp.SetUserPreferenceIntegerValue(
(int)swUserPreferenceIntegerValue_e.swDxfMappingFileIndex, idx);
A common mistake is picking a mapping file in the GUI, then a macro resets the index to -1 without realising. Validate after every set:
int active = swApp.GetUserPreferenceIntegerValue(
(int)swUserPreferenceIntegerValue_e.swDxfMappingFileIndex);
if (active != idx)
throw new InvalidOperationException($"Mapping did not stick: got {active}");
The layer mapping file itself is plain text, one line per category:
Visible Edges;OUTLINE;7;CONTINUOUS
Hidden Edges;HIDDEN;8;HIDDEN
Bend Lines Up;BEND_UP;3;DASHED
Bend Lines Down;BEND_DOWN;4;DASHED
Sketch Entities;ETCH;5;CONTINUOUS
Construction Geometry;CONSTRUCTION;9;CONTINUOUS
Forming Tool Centerlines;FORM_CL;6;CENTER
Cosmetic Thread;THREAD;2;PHANTOM
Library Features;LIB;1;CONTINUOUS
Fabricators that accept DXFs over email care deeply about layer names. When the DXF arrives on layer 0 with everything jumbled, their nest software either skips the bend lines or treats them as cuts. The mapping file is what stops that from happening.
Construction geometry leaks into DXF even when you check “exclude hidden sketches”
A recurring question: reference sketches marked as construction-only still appear in the DXF. The checkbox “exclude hidden sketches” does not suppress them, because “construction” and “hidden” are independent flags. The export pipeline reads the IncludeSketches bit from the bitmask. If it is on, all sketches on the flat pattern face are written, regardless of visibility state.
The workaround most engineers never find: mark individual sketch entities as For Construction in the sketch editor (right-click the entity → For Construction). Construction geometry is a per-entity flag that the export pipeline treats as a separate category — mapped via the Construction Geometry row in the layer mapping file. You can now leave IncludeSketches = 1 for etch marks, send construction reference lines to a throwaway layer your laser operator ignores, and stop manually deleting lines after every export.
A full working export call
Putting the pieces together, this is what a batch export looks like when you do not trust defaults:
// Set the tolerance sanely — the user preference is shared with the dialog.
swApp.SetUserPreferenceDoubleValue(
(int)swUserPreferenceDoubleValue_e.swExportDxfMaxGap, 0.0000254); // 0.0254 mm
// Pin the mapping file.
SetActiveMappingFile(swApp, "laser-cut.txt");
// Build the bitmask explicitly. Do not rely on dialog state.
const int options =
(int)swExportFlatPatternOption_e.swExportFlatPatternOption_ExportFlatPatternGeometry |
(int)swExportFlatPatternOption_e.swExportFlatPatternOption_ExportBendLines |
(int)swExportFlatPatternOption_e.swExportFlatPatternOption_IncludeSketches |
(int)swExportFlatPatternOption_e.swExportFlatPatternOption_MergeCoplanarFaces |
(int)swExportFlatPatternOption_e.swExportFlatPatternOption_ExportBoundingBox;
// Alignment: force flat pattern to world origin, X along world X.
object align = new double[] { 0, 0, 0, 1, 0, 0 };
bool ok = partDoc.ExportToDWG2(
outputPath,
partDoc.GetPathName(),
(int)swExportToDWG_e.swExportToDWG_ExportSheetMetal,
false, // bViewsIntoOneDoc
null, // varViews
true, // bExportFlat
false, // bAllowScale — scale should be 1:1 for laser
options,
align);
Two details that trip people up:
bAllowScaleshould befalsefor manufacturing. If any drawing-scale property other than 1:1 is present, atruevalue will silently scale the DXF. Fabricators receive a part 25 mm across that should have been 100 mm.- The alignment array is a
double[6]. Some versions of the API help show 5 elements — that is wrong. Origin is three doubles, X-axis direction is three doubles. Six total.
For the full path from API call into the CATIA CGM kernel and why the export is slow, see how SolidWorks creates flat patterns.
Where CadShift fits
CadShift sets these defaults automatically. End point merging tolerance picks 0.001 in or 0.025 mm based on the active document unit. The entity bitmask is pinned per export profile, so the same options apply across every run — no re-ticking the dialog when you batch-export 40 parts from an assembly. Layer mapping is bound to a profile and validated before each export so you never silently fall back to layer 0. Construction geometry is honoured as a separate category, not merged with sketches.
It is the same set of decisions you would make writing a macro from scratch, except you do not have to write the macro and the settings do not drift over time.
What to check on your next export
Before you commit to the next batch, take 30 seconds:
- Tolerance check. Open Tools → Options → Export → DXF/DWG. Is the max gap
1.0? If yes, change to0.001 inor0.025 mm. Reopen the dialog afterward to confirm it stuck. - Mapping file check. Save As → DXF → wizard. Is the mapping file still the one you set last week, or does it say
<none>? If it reset, reapply it through the API — the GUI alone does not persist it across user profile refreshes. - Entity flags. Bend lines ticked. Construction geometry off if you do not want reference lines. Hidden edges off unless you genuinely need them.
- Scale. Set to 1:1. Any other value is almost always a bug.
If the same four checks happen 40 times a day in your shop, you already know where the time actually goes on a batch export. The defaults do not change themselves. And if the DXF is destined for a laser cutter, there are additional workflow steps on the CAM side that the entity settings alone do not control — see AutoCAD DXF laser cutting workflow for what happens after the file leaves SolidWorks.