Components offset from board in STEP export

When I export a PCB as a STEP file, I’ve noticed that all of the components are positioned 0.05mm off the surface of the PCB. Since I’m using these STEP files for testing mechanical assembly with connectors, checking alignment and clearance, I’d really like to not have it do this.

I did some digging into the STEP exporter code, and this behavior appears to be intentional and hard-coded. The relevant code can be found here:

(The actual lines have been moved around across many refactorings, so their exact location may be different on newer or older branches of the code.)

When trying to look back through the history of this code, the offset behavior dates all the way back to when the kicad2step code was originally merged into the source tree. No explanation was provided that I can find.

I really want to disable this behavior, so my components in exported STEP files are flush with the surface of the PCB as they are in KiCad’s built-in 3D board viewer. I’m just trying to figure out the path forward here before I open any sort of actual issue/ticket.

The options I see as possible are:

  1. Remove the board offset from the STEP exporter code
  2. Make the board offset a configurable option for the STEP export process (presented via the export dialog and/or command line parameters)
  3. Make the board offset dependent on the PCB stackup settings, where I can pick ones that make it effectively zero

Any thoughts?

In the short term, my workaround is to simply have my own source build of KiCad v7 where I’ve commented out the above-mentioned lines. This works, but is not a convenient or ideal solution.

Amusing myself over hot cup of Black Coffee, I put together a screenshot and info as follows:

First! The digital world has corrupted commonsense-thinking. You indicate concern about 0.05mm. That value is one-half the thickness of average Human Hair! Do you really think such a tight dimension and control of that value in manufacturing/tolerances (at the low cost of most PCB’s) is something your project needs? Are you worried about interference contact at that close proximity to other Physical parts (if so, I’m biting my tongue, so to speak…)

Now, to the point:

The image below shows (on Left side) PCB, Encoder (grey) and Multi-Switch (blue).

The White lines are the Silk-Screen in the 3D-Viewer and shows the Multi-Switch sitting on top of Silk. It also shows the Z-height setting for the Multi-Switch set at Zero.

On the Right side, you see initial 0.25mm Gap of Encoder and below it’s reset to Zero and sitting on top of the Silk (like the Multi-Switch).

Also on the Right, you see the PCB/Parts loaded into FreeCAD and the STEP loaded into FreeCAD. Both the Encoder and the Switch are located at correct Z-height’s (Note: the Switch is not shown because it’s a WRL and doesn’t get exported as STEP from Kicad).

1 Like

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.