Duplicate all reference designators to the fabrication layer

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.

It sounds like what you want is the default KiCad footprint style, where both the value and the ref des appear on the Fab layer?


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:

  (fp_text user "${REFERENCE}" (at 0 0) (layer "F.Fab")
    (effects (font (size 0.8 0.8) (thickness 0.12)))
    (tstamp f76b5b71-f784-4fa2-a423-99e4954ebe12)
  )

So you could add lines like that to each of your kicad_mod files? Would that work?

Yeah, the footprints were not made by me and are not default KiCad’s…

Editing the text file is an option but I consider it “last resort” as it is done out of KiCad and one can easily mess something.

I suppose that python script could do it too.

But I was wondering if there is any simple GUI way that I am missing…

So I went the Python route and it showed to be a reasonably straight forward way…

Few notes:

  1. 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

  2. I diffed the output and input files to check that only the fp_text user … sections changed

  3. 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')

The code is a mixture of Programmatic Layout with KiCad and Python | Jeff McBride and Kicad Python bindings: Proper way to create or copy FP_TEXT to add to FOOTPRINT? - #13 by gwideman

1 Like

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