Python: How to batch-hide silkscreen text of specific items?

I have a full-fledged board with hundreds of components.
To care for a sane silkscreen design, I want to remove all unnecessary cluttering.
Especially fiducials and other stuff that isn’t actually a “part” (or a super obvious part not needing a reference indication) are things I want to get rid of their textual contribution. “FID15” just makes no sense.

Great opportunity for writing a few simple python lines, I thought.
So, I want to programmatically toggle the “show” checkbox you can find when you right-click a footprint, -> choose “edit” and look for the rows “Reference” and “Value” in the table. Nothing more.

I didn’t find ANY useful Kicad Python API documentation at all, not even mentioning something more special like this. So I tried … … (simplified code for clarity)

modules = board.GetModules()
for mod in modules:
    if (mod.GetReference().startswith("FID")):
        mod. xyz ()

with “xyz” being one of the plenty functions to retrieve flags and status and everything just to see if there’s one bit I can toggle to make reference and/or values invisible.
Beforehand, I of course changed some fiducials by hand to enable me see differences, but apart from seeing which FID was selected / highlighted in PCBNew, I didn’t find any reasonable answer.

Has anyone here any kind of documentation or even a small snippet that explains what I need to do?

Thank you!

mod.Reference().SetVisible(False)
1 Like

Thank you very much!
I was sticking too much to getters / setters to notice and thought, both would return the same.

This works great now:

CLEAN = ["FID", "GX", "H", "JP", "J", "NT", "TP"]
modules = GetBoard().GetModules()

for m in modules:
    ref = m.GetReference()

    # Hide reference when on the black list
    if any(test in ref for test in CLEAN):
        m.Reference().SetVisible(False)
    else:
        m.Reference().SetVisible(True)
    
    # Hide all values
    m.Value().SetVisible(False)

    # Hide other text in footprints (like capacitors)
    gi = m.GraphicalItems()
    for item in gi:
        if (item.GetClass() == "MTEXT"):
            item.SetVisible(False)

Refresh()

The one thing remaining is finding how to also switch off a third text item some footprints have, which is denoted as “%R” in many of them and also appears in the list, right beneath Reference and Value.

EDIT: Found it, see above, last block in code.

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