Get all symbols/footprints excluded from BOM

Ideally I wanted to search for all symbols that I had checked off the “Exclude from bill of materials” as I wasn’t sure if I had mistakenly done this on some parts of a large project. I didn’t see any way to search for them using the GUI, so I resorted to some python. Here is what I came up with. Maybe it will be useful to others, though it only works with footprints as I don’t know of a way to access a list of symbols using pcbnew. If anyone knows of this, I’d be happy to revise.

# See for enum definitions

import pcbnew
import sys
from enum import Enum

board = pcbnew.LoadBoard(sys.argv[1])
footprints = board.GetFootprints()

    FP_THROUGH_HOLE             = 0x0001
    FP_SMD                      = 0x0002
    FP_EXCLUDE_FROM_BOM         = 0x0008
    FP_BOARD_ONLY               = 0x0010  # Footprint has no corresponding symbol
    FP_JUST_ADDED               = 0x0020  # Footprint just added by netlist update
    FP_DNP                      = 0x0100

for footprint in footprints:
    attr = footprint.GetAttributes()
        print(footprint.GetReference() + " is excluded from BOM")
    # This doesn't seem to match anything for some reason.
    if attr & FOOTPRINT_ATTR_T.FP_DNP.value:
        print(footprint.GetReference() + " is DNP")

Also not sure why none of my DNP parts are not printing here. Looking at a single footprint in the PCB Editor it looks like this isn’t even a footprint attribute but only saved to the symbol so maybe that is why? Ideally I’d like to be able to print a list of those as well.

Also curious if this Enum can be accessed from within the pcbnew or if my copy/paste from the cpp code was necessary.


Adding KiCAD version info:

Application: KiCad PCB Editor x86_64 on x86_64

Version: 7.0.6-7.0.6~ubuntu22.04.1, release build

wxWidgets 3.2.1
FreeType 2.11.1
HarfBuzz 6.0.0
FontConfig 2.13.1
libcurl/7.81.0 OpenSSL/3.0.2 zlib/1.2.11 brotli/1.0.9 zstd/1.4.8 libidn2/2.3.2 libpsl/0.21.0 (+libidn2/2.3.2) libssh/0.9.6/openssl/zlib nghttp2/1.43.0 librtmp/2.3 OpenLDAP/2.5.14

Platform: Ubuntu 22.04.2 LTS, 64 bit, Little endian, wxGTK, ubuntu-xorg, x11

Build Info:
Date: Jul 7 2023 02:32:39
wxWidgets: 3.2.1 (wchar_t,wx containers) GTK+ 3.24
Boost: 1.74.0
OCC: 7.5.2
Curl: 7.88.1
ngspice: 38
Compiler: GCC 11.3.0 with C++ ABI 1016

Build settings:

1 Like

You should specify version of KiCad this applies to because python interface is not stable across versions.

For what it’s worth, there is new functionality that is equivalent in v8 (in development):

1 Like

Added an edit, thanks.

FP attribute enum values are exposed in pcbnew module, you can check here KiCad Pcbnew Python Scripting: pcbnew Namespace Reference
Search for FP_EXCLUDE_FROM_BOM for example

DNP will not print because separate attribute for it was not a thing in v7, it was added later for future v8. Check the footprint.h from 7.0 branch.

1 Like

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