[SOLVED] How to load footprint from library

Hi,
my question is not related to a specific plugin, but rather a general Python API one.

I’m trying to load a footprint from library and place it on a board.
I do it with the following code.

KICAD_VERSION = pcbnew.Version().split(".")[0]
fp_path = os.getenv("KICAD" + KICAD_VERSION + "_FOOTPRINT_DIR", default=None)

fp_lib = fp_path + "Connector_Wire.pretty"
fp = "SolderWire-0.15sqmm_1x01_D0.5mm_OD1.5mm"

m = pcbnew.FootprintLoad( fp_lib, fp )
m.SetReference("T1")

# position been generated elsewhere
m.SetPosition(xy)

# board been generated elsewhere
board.Add(m)

However, this leaves the DRC partially unhappy:

image

If I compare the footprint properties with the same footprint manually added, the “link” misses the reference to the library name, and just contains the footprint name

BAD

GOOD

how can I fix this?

thx

Use SetFPIDAsString() method on the footprint

awesome thx. that was “qu1ck” and worked like a charm with

m.SetFPIDAsString( <lib_name> + ":" + <lib_footprint>)

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