I’m wondering what the proper workflow is to create boards, place footprints, add tracks, etc… with Python in Pcbnew. I’m using Windows, so I can only source scripts from the Pcbnew scripting console. I want to create a new board and place components, and periodically run the script to make a board from scratch see how my math is working out. To get to the scripting console, I need to start a blank Pcbnew project. If I run
board = pcbnew.GetBoard() mod = pcb.FootprintLoad(lib_location, "RF_SMA_Vertical_5-1814832-1"); position1 = pcbnew.wxPoint(0,0); mod.SetPosition(position1) board.Add(mod) pcbnew.Refresh() board.Save(new_filename) pcbnew.Refresh() os.startfile(new_filename)
Then I see the existing empty board get populated, and the “new_filename” board opens up as well with the part populated. If I close “new_filename” and run the script again, I get a duplicate part placed on top of the original file. This leads me to believe that GetBoard() is just always getting the board from which the scripting console was opened from.
I want to be able to run this script again and again and start from scratch every time. Once I save “new_filename”, I’ve also tried doing
board = pcbnew.LoadBoard(new_filename) board.Save(filename)
But I get the same issue. I don’t see a way to display the new board without saving it first, which leads to the overwriting of parts issue.
I see this script here which includes these lines:
for t in pcb.GetTracks(): pcb.Delete(t) for d in pcb.GetDrawings(): pcb.Remove(d)
However, pcb.GetDrawings() returns nothing for me. Does it only return schematic drawings? The docs have a function Board.Footprints() here which look like they should return all the footprints on a board. But my version (5.1.3) doesn’t seem to have that function. And the docs page seems to be based on an even earlier version (4.0.0 according to this header here).
So to summarize, is there an easy workflow to be able to adjust an entire script while continually running it as you go, without getting all your parts overlapped on the old versions?