Every mechanical engineer who works with sheet metal in SolidWorks has clicked Export DXF/DWG hundreds of times. The flat pattern appears, a file lands on disk, and you send it to the laser cutter. But what actually happens between clicking that button and getting a flat DXF? Why is it slow? And why does the orientation sometimes feel random?

We spent time digging into the SolidWorks API documentation, decompiling DLLs, and examining exported symbols to understand the full pipeline — the same approach we used when investigating how SolidWorks drawing files store geometry internally. Here’s what we found.

The flat pattern already exists

The first thing to understand is that SolidWorks doesn’t compute the flat pattern from scratch when you export. Every time you create a sheet metal feature — base flange, edge flange, hem, jog — SolidWorks simultaneously computes and stores a Flat-Pattern feature in the feature tree. It’s normally suppressed (collapsed under the Flat-Pattern folder), but the geometry is already there.

When you trigger a DXF export, SolidWorks unsuppresses that feature, extracts the 2D geometry, writes the file, and suppresses it again.

Two ways to export

The SolidWorks API provides two distinct approaches:

Direct export with ExportToDWG2

This is the standard method. You select the flat pattern feature and call IPartDoc.ExportToDWG2(). SolidWorks handles everything internally — no intermediate drawing document is created. The method takes a bitmask that controls which elements to include: profile edges, bend lines, hidden edges, sketches, library features, forming tools, and bounding box.

Drawing-based export

The alternative is to create a temporary drawing, call IDrawingDoc.CreateFlatPatternViewFromModelView3() to place the flat pattern as a drawing view, then save the drawing as DXF. This gives you more control over the view (you can flip it, position multiple flat patterns on one sheet), but it’s heavier.

Most add-ins, including CadShift, use the direct method for individual parts and fall back to the drawing method for special cases.

What happens inside SolidWorks

When ExportToDWG2 executes, the call crosses from your add-in’s .NET process into the native C++ SolidWorks process via COM. From there, the work is handed to the CATIA CGM kernel — the geometric modeling engine that Dassault Systemes uses across SolidWorks, CATIA, and other products.

Here’s the chain:

Step 1: Unsuppress and regenerate

The flat pattern feature is activated in memory. This triggers a feature regeneration — the CGM kernel rebuilds the flat body’s boundary representation (B-Rep). This is why the part must be visually open and active: SolidWorks’ feature tree only resolves when the document is in the foreground.

Step 2: Topology decomposition

The 3D sheet metal body is decomposed into a graph of faces and edges. Each planar face is a node. Each cylindrical face (a bend) is an edge connecting two nodes. The kernel uses classes like CATSHMBody, CATSHMFace, and CATSHMEdge (found in catsheetmetaloperators.dll) to represent this topology.

Step 3: Choose the root — the fixed face

Every flat pattern has a fixed face — the face that stays in place while everything else unfolds around it. By default, SolidWorks picks one automatically (typically the largest face). You can change it via the FlatPatternFeatureData.FixedFace2 API property.

The fixed face determines:

  • Which side of the sheet faces “up” in the flat pattern
  • The base orientation of the 2D output
  • Where the flat pattern is anchored in coordinate space

Step 4: Bend-by-bend unfolding

Starting from the fixed face, each adjacent face connected by a bend is rotated flat around the bend axis. This is a rigid body transformation — the planar faces don’t deform, only the bends are straightened.

The rotation propagates recursively through the bend graph. If face A connects to face B via bend 1, and face B connects to face C via bend 2, then:

  • Face A stays fixed
  • Face B rotates about bend 1’s axis by the bend angle
  • Face C inherits B’s rotation and then rotates about bend 2’s axis

Step 5: Compute the developed length (K-factor)

This is the critical calculation. When you bend a piece of sheet metal, the material on the outside stretches and the material on the inside compresses. Somewhere between the inner and outer surface there’s a neutral axis — the plane that neither stretches nor compresses.

The K-factor tells you where that neutral axis sits:

  • K = 0 → neutral axis at the inner surface
  • K = 0.5 → neutral axis at the center of the sheet thickness
  • K = 1 → neutral axis at the outer surface

The flat length of each bend is:

flat_length = (pi * bend_angle / 180) * (bend_radius + K * thickness)

This determines the gap between adjacent flat faces — how much material the bend “consumes” when flattened. Get it wrong and the part won’t fold to the right dimensions.

SolidWorks supports several methods:

  • K-factor — a direct value, either global or per-bend
  • Bend allowance — the flat length specified directly
  • Bend deduction — the amount subtracted from the sum of flange lengths
  • Bend table — a lookup table indexed by material, thickness, radius, and angle

Step 6: Map 3D to 2D coordinates

The CATIMapDevelop interface (in catsheetmetalinfra.dll) handles the mathematical transformation from the 3D folded body to the 2D flat pattern. It takes every point on the 3D surface and maps it to a 2D coordinate in the flat layout.

Step 7: Handle formed features

Formed features like louvers, lances, dimples, and embosses can’t simply be unfolded — they involve plastic deformation, not just bending. The CATSmdUnfoldStampOperator (in catsmdunfoldstamp.dll) handles these by analyzing the stamp geometry and projecting a 2D outline into the flat pattern. This is why formed features appear as simple outlines in the DXF rather than their full 3D shape.

Step 8: Classify edges and write DXF

Finally, SolidWorks takes the 2D geometry and classifies every edge:

  • Profile edges — outer boundary of the flat body
  • Bend lines — where the bends were (up or down)
  • Hidden edges — edges from cuts or features on the back side
  • Sketch geometry — any sketches included in the flat pattern

Each category goes to a different DXF layer — and getting these layers right is what fabricators actually need from a DXF file. Then the DXF file is serialized to disk.

This last step — writing the DXF file — is the slowest part of the entire process. The flat pattern computation is fast. The file I/O through SolidWorks’ internal DXF writer is what takes the time.

Why it’s slow

Three factors contribute:

  1. Single-threaded COM — SolidWorks uses Single-Threaded Apartment (STA) COM. All geometry operations and file I/O run on the main UI thread. Nothing can be parallelized.

  2. The part must be active — you can’t export a flat pattern from a background document. The feature tree needs to be fully resolved in the active document context.

  3. SolidWorks’ DXF writer — the internal DXF serialization is not optimized for speed. For complex parts with many edges, the writing step dominates the total export time. The flat pattern geometry is ready in memory long before the file finishes writing.

If you’re batch-exporting dozens of sheet metal parts from an assembly, this adds up quickly. Each part needs to be activated, its flat pattern resolved, and the DXF written serially.

The alignment array mystery

The ExportToDWG2 method accepts a 12-element double[] alignment array that’s supposed to control the output orientation:

ElementsMeaning
[0, 1, 2]New origin (x, y, z translation)
[3, 4, 5]New X-axis direction vector
[6, 7, 8]New Y-axis direction vector
[9, 10, 11]Normal vector to selected faces

The official example uses the identity transform:

alignment = { 0,0,0,  1,0,0,  0,1,0,  0,0,1 };
//            origin   X-axis   Y-axis   normal

The problem

The API documentation buries this critical detail:

“The last three elements of the array are valid only if Action = swExportToDWG_ExportSelectedFacesOrLoops”

For sheet metal export (Action = 1), elements [9, 10, 11] are ignored. But it’s worse than that: in practice, SolidWorks ignores the entire alignment array for sheet metal exports. The output orientation is determined by:

  1. The fixed face’s plane — provides the Z direction
  2. An internal heuristic — SolidWorks picks an edge on the fixed face (usually the longest) to determine the X/Y directions

Different parts with different geometry will orient differently. The same part can orient differently if you change the fixed face. And the alignment array you pass has no effect on any of it.

What does control orientation

For sheet metal DXF output, only these actually work:

  • IsXDirFlipped / IsYDirFlipped — mirror the output along X or Y. These work reliably but only flip, not rotate.
  • The fixed face — changing FlatPatternFeatureData.FixedFace2 changes the base orientation, but you can’t predict which direction it’ll choose for X/Y.

This is why most serious SolidWorks add-ins handle orientation in post-processing rather than relying on the API parameters. For more on the K-factor and dimension challenges in flat pattern export, we covered that in a separate post.

How CadShift handles it

Since the alignment array is unreliable, CadShift passes null and handles orientation after the fact:

  1. Export the DXF with default orientation
  2. Read it back using the netDxf library
  3. Count bend directions — if more bends are “down” than “up,” flip the DXF so the majority side faces up
  4. A-face override — if the user has explicitly marked which side should face up (the cosmetic/protected side), skip the auto-flip and trust the FixedFace2 orientation that was set during marking
  5. Compute bounding box using a convex hull algorithm, because SolidWorks’ built-in bounding box option draws it incorrectly on the edges

This read-modify-write cycle adds some time, but it guarantees consistent, predictable orientation regardless of what SolidWorks decides to do internally.

The SheetMetalOptions bitmask

For reference, here’s what each bit in the SheetMetalOptions parameter controls:

BitValueWhat it includes
11Flat-pattern geometry (profile edges)
22Hidden edges
34Bend lines
48Sketches
516Merge coplanar faces
632Library features
764Forming tools
122048Bounding box

Bits 8 through 11 are reserved and must be 0.

Takeaways

  • The flat pattern geometry is pre-computed and stored in the feature tree. Export is mostly about serialization, not computation.
  • The CATIA CGM kernel handles the actual unfolding math — bend-by-bend rigid rotation with K-factor-based developed length calculation.
  • The alignment array in ExportToDWG2 does not reliably control sheet metal DXF orientation. Don’t waste time trying to make it work.
  • The DXF writing step is the bottleneck, not the geometry computation.
  • For consistent orientation, post-process the DXF output rather than relying on API parameters.
  • If you recently upgraded to SolidWorks 2025, some flat pattern behaviors changed — see what changed in SolidWorks 2025 flat pattern processing for the specific issues and workarounds. For how the DXF you export interacts with kerf compensation in downstream laser cutting software, see kerf compensation in laser cutting DXF files.