How to create "Footprint Position" file with pcbnew.py?


#1

For MSEkicadBOM


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?

Thanks, Martin


#2

Yes, a simple example would help. Can someone please post one?


#3

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:

kicommand.run("modules GetCenter call")

In python after import kicommand.


#4

Thanks, but not really what I wanted.

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.)


#5

Steps in python:

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.)


#6

Excellent, many thanks!

Exactly what I needed, and very very simple.