Question: Python scripting

Hi guys,

The Python API that we currently have lacks a lot of features - it’s a work in progress and will be changed and extended in the future.

Concerning the undo & view update stuff (the annoying F9/F11 thing you mentioned): we are going to expose the COMMIT class to Python. Commits let you update the BOARD and the associated views/observers in an atomic way as well as create undo buffer entries. For example:

# modification of a via diameter and adding a track. "via" comes from the existing BOARD object, track is a new item created by the script
commit = pcbnew.COMMIT()
# inform PCBnew that we're going to modify the via object
commit.Modify(via)
via.SetDiameter()
track = TRACK()
track.SetStart(...)
track.SetEnd(...)
# add a new item (track) to the commit
commit.Add(track)
# push the commit - this will update the board view, connectivity (ratsnest), commit changes to the BOARD object and create an entry in the undo buffer
commit.Push("Change a via and add a new track") 

Also, I’m considering exposing functions for manipulating the selections in PCBnew - initially a few functions to add/remove items to the selection and retrieve the current selection. With these, I hope, script development will be much easier.

I’ll try to push the changes to the nightly build within a couple of weeks.

Tom

7 Likes