I have a project where all footprints have their values on fabrication layers and their reference designators on respective silk screen. That is fine and I would like to keep it that way.
However I would like to add second field with the reference designators to the respective fabrication layers. Is it possible to achieve this for all footprints at once? I tried the Edit texts… tool and I was able to hide the values with it but I did not find a way how to add texts with it.
But you’re saying the footprints you have don’t have this entry in the properties?
If it’s not there, I suppose the best you can do is add it one by one. This could be quite easy to do by editing the .kicad_mod files in a text editor.
For example, if I open the R_1206_3216Metric.kicad_mod file (corresponding to the example in the screenshots above) in a text editor, I see these lines:
So I went the Python route and it showed to be a reasonably straight forward way…
Few notes:
It seems that for write operations it is better to use Python outside of KiCad and not in the python console. I may be wrong but a lot of forum posts I found were solving issues with it… And I have a simple docker container with all needed tools ready so it is very easy to do so
I diffed the output and input files to check that only the fp_text user … sections changed
The code is not perfect it is a one use script and it served its purpose… So no error checking, etc…
import sys
import pcbnew
if __name__ == "__main__":
def find_layer(board, layer_name):
for i in range(128):
if board.GetLayerName(i) == layer_name:
return i
return -1
project_file = sys.argv[1]
board = pcbnew.LoadBoard(project_file)
FCuId = find_layer(board, "F.Cu")
BCuId = find_layer(board, "B.Cu")
BFabId = find_layer(board, "B.Fab")
FFabId = find_layer(board, "F.Fab")
for footprint in board.GetFootprints():
if footprint.IsOnLayer(FCuId) or footprint.IsOnLayer(BCuId):
newitem = pcbnew.FP_TEXT(footprint)
newitem.SetText("${REFERENCE}")
newitem.SetLayer(FFabId if footprint.IsOnLayer(FCuId) else BFabId)
newitem.SetVisible(True)
footprint.Add(newitem)
board.Save('test.kicad_pcb')