KiCad PCBNew Scripting: Removing Ref Des From Silk Screen
Purpose
Most boards I design include reference designators on the silkscreen. This way, during bring-up, I can rely solely on the schematic, BOM, and board—no need to cross-reference with CAD. When doing a tight design it may not be possible to fit the labels anywhere that might actually be useful. When that happens you may want to forgo the labels on the silkscreen entirely. The labels are nice to have but are secondary to the operation of the circuit, nicely labeled but nonfunctional is hardly a good trade-off. Here’s what I’m looking at when deciding to remove the silkscreen ref des:
Tight layout without space for silkscreen ref des
The labels do need to go somewhere, if they are not on the silkscreen you will need to put them on another layer. The placement of those labels are typically the only way assemblers know how to match the BOM to the pads. The standard KiCad library has the ref des on the fabrication layer and on the silkscreen, for assembly you will only need to check that this is visible on the fabrication layer for all parts. When doing board bring-up I print out the fabrication layers with the board outline as a guide. The part ‘R1’ below has the large label on the silkscreen and the small label in the center on the fabrication layer.
0402 Resistor from KiCad Library
So I have the labels placed as needed for each part on the fabrication layer but can’t fit them on the silkscreen. The manual method is to click on every part/label and set it be invisible (or change the layer). This is time consuming at best and error prone at worst.
pcbnew Scripting
Documentation for the pcbnew API is slim. I got going by reading the tutorials here. My method has been using the scripting interface in the GUI (this can be done with whatever python environment you prefer but there’s a couple more steps).
I want to set the reference field of every part to be invisible, leaving only the fabrication label present (which is a different field entry so will be unaffected). For scripted testing of boards it would be worthwhile checking the fabrication label is set to visible and has the value ${REFERENCE}.
Example Board
I’m using this as the example board:
Example board
Code
import pcbnew
board = pcbnew.GetBoard()
for part in board.Footprints():
ref = part.Reference()
print(ref.GetText())
print(ref.IsVisible())
ref.SetVisible(False)
print(ref.IsVisible())
The terminal output is:
C2
True
False
C1
True
False
The GUI editor doesn’t update automatically to the changes, the labels are still visible but aren’t interactive. To update the view I run “Update All Footprints From Library” which now has the silkscreen reference set to not visible. Result:
{width=“750”}
Summary
Hiding silkscreen reference designators is sometimes necessary in dense designs. With KiCad’s scripting interface, you can automate this process reliably—avoiding tedious manual edits while preserving fab and assembly layer info. Whether you’re doing bring-up or preparing a board for assembly, scripting can save time and reduce error.
Update
I’ve been using this enough to make a plugin for it:
https://github.com/snhobbs/SetReferenceVisibility
Turns out you can do this with the “Edit -> Edit Text and Graphic Properties” menu.
Doxygen documentation for the API is available here.