I need to create the same output as by pcbnew ‘File’-‘Fabrication Outputs’-‘Footprint Position (.pos) File’. I was told that it is possible “with a few lines of Python Code”. I learned that not all functions in pcbnew.py are working or are intended to be used. So I dare to ask here first before I again spend days with pcbnew.py and doubtful results. Does anybody know how it can be achieved?
With KiCommand, you can get the center positions with the following command:
modules GetCenter call print
Edit to add: the new KiCommand makes it easy to use KiCommand within python. By default the kicommand.run(commandstring) function returns the top of the stack, so you would get, in this case, a list of the center wxPoints of the modules. So you can run:
I already have a Python program that autodetects changes and produces gerbers and PDFs for a series of PCBs, I just want to add position export.
(I appreciate people contributing, but installing and learning a completely new tool for this simple task—I’d rather spend the time learning the Python interface.)
import pcbnew
for m in pcbnew.GetBoard().GetModules():
c = m.GetCenter()
print m.GetReference(), c.x, c.y
And replace the print statement with any formatting you need. (I can’t remember whether GetReference() returns the text and Reference() returns the EDA_TEXT or vice versa.)