Problem adding new parts using python

Hello! I’m playing around with dip soldering and I’m working on a script to create SMD pads/footprints at every through hole pad on a PCB so that I can order a solder stencil, but instead of using it as a solder paste stencil I’m using it as a mask for dip soldering parts.

I’ve got most of it worked out, but the issue I can’t seem to figure out, is how to add footprints and set their position.

I have it working to place the footprint, but when I try to move it I get an error in Python. When I try to add multiple parts it groups them together, and I can’t even manually move them.

Any ideas what I’m doing wrong? Here is the boiled down test script I’m trying to get working:

import pcbnew

# get current board
pcb = pcbnew.GetBoard()

# load the footprint
dipSolderFootprint = pcbnew.FootprintLoad(r"C:\Users\Ben\Documents\Dropbox (Curly Tale Games)\MaxFeederShield\Lib\arduino-kicad-library\DipSolderFootprints.pretty","DipSolder4mm")

# create the part
dipPart1 = pcb.Add(dipSolderFootprint)
dipPart2 = pcb.Add(dipSolderFootprint)
dipPart3 = pcb.Add(dipSolderFootprint)

# move the part into position
# dipPart.SetPosition(pcbnew.wxPoint(128500000, 50500000))
# returns error: AttributeError: 'NoneType' object has no attribute 'SetPosition'

# update pcbnew display
pcbnew.Refresh()

Thanks!!

You need to create separate instances of the footprint. Once you loaded it from library you can create copies with fp2 = fp.Clone(). Calling Add(fp) actually attaches the footprint to the board, it doesn’t create the footprint.
You get the no attribute error because you are calling SetPosition() not on a footprint object but on something else.

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