KiCAD PCBNew Scripting: Removing Ref Des From Silk Screen

Tight layout without space for silkscreen ref. des.

Purpose

Most boards I make have the reference designators on the silkscreen, that way when doing board bring-up I only need the schematic, BOM, and board. 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.{width=“859” height=“521”}

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{width=“346” height=“430”}

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{width=“750”}

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:

Example board with reference designators set to not visible{width=“750”}

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 Text and Graphics Properties” menu.

Doxygen documentation for the API is available here.