Question: Python scripting

To the pcbnew python scripting experts out there:

I am running the interactive python shell from within Pcbnew, and am able to modify board elements. Two issues:

  1. How do I “update” or “refresh” the board from the script? If I move a module it does not move on the screen (until I click on it). If I add a track or a pad, it does not appear on the screen, but it is present in the pcbnew.GetBoard() object

  2. Is there a way to save an undo/redo action? I would like to programatically make save-points as I go.

  1. Is a known problem. To see the new elements, switch canvases and back (F9, F11).

  2. I don’t know :frowning: I’ll be monitoring this for answers from others!

2 Likes
  1. That’s disappointing. I shall try to investigate this.

  2. Undo / redo would be handy to expose to python too.

1 Like

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

Tom,

The changes that you outline are literally all that I need for the grand ideas that I have in mind. I look forward to seeing your changes committed to nightly.

2 Likes

twl’s response probably addresses the elements not appearing until canvas change. But just for reference, here are some posts and bugs that are related:


Possibly:
https://lists.launchpad.net/kicad-developers/msg30372.html

2 Likes