Back in November I was in a thread about board_commit:
https://lists.launchpad.net/kicad-developers/msg32063.html
The topic had come up in another patch:
https://lists.launchpad.net/kicad-developers/msg32134.html
See attached path file. added needed code to SWIG to enable using
BOARD_COMMIT
As a basic test, I ran the attached commit.py [1] on the attached
commit.kicad_pcb. It just moves some modules and adds some vias. undo
seems to work fine and (perhaps more important) the canvas updates
correctly (there are some bugs in fresh that I haven't figured out)
I have also updated some of my other scripts to use it and almost all
seems well.
*
*
*The thing that doesn't work...*
If I run a script as an external plugin, undoing, brings me back to an
empty canvas. I don't know how to debug that. Some guidance could be
helpful. I don't think this is a problem in the python interface, but
rather some multi-threading thing in BOARD_COMMIT itself.
Here's a demo of the problem:
https://youtu.be/YR-9dx_lkUo
place_by_sch described in the video is here:
https://github.com/mmccoo/kicad_mmccoo/blob/master/place_by_sch/place_by_sch.py
The board_commit stuff isn't in that version[2]
Miles
[1] I have a feeling the py file will be filtered, so here it is
toplayer = layertable['F.Cu']
bottomlayer = layertable['B.Cu']
for mod in board.GetModules():
print("mod {}".format(mod.GetReference()))
newvia = pcbnew.VIA(board)
board.Add(newvia)
newvia.SetNet(gnd)
nc = gnd.GetNetClass()
newvia.SetWidth(nc.GetViaDiameter())
newvia.SetPosition(mod.GetPosition())
newvia.SetLayerPair(toplayer, bottomlayer)
newvia.SetViaType(pcbnew.VIA_THROUGH)
bc.Added(newvia)
bc.Modify(mod)
mod.SetPosition(pcbnew.wxPoint(mod.GetPosition().x +
pcbnew.Millimeter2iu(10),
mod.GetPosition().y +
pcbnew.Millimeter2iu(10)))
bc.Push("moved stuff")
[2]
diff --git a/place_by_sch/place_by_sch.py b/place_by_sch/place_by_sch.py
index 22bc21c..5f70354 100644
--- a/place_by_sch/place_by_sch.py
+++ b/place_by_sch/place_by_sch.py
@@ -7,7 +7,9 @@ import re
def PlaceBySch():
board = pcbnew.GetBoard()
-
+ print("getting board commit")
+ bc = pcbnew.NewBoardCommit()
+
board_path = board.GetFileName()
sch_path = board_path.replace(".kicad_pcb", ".sch")
@@ -114,9 +116,10 @@ def PlaceBySch():
# oldvalue * 25.4 / 10e4
newx = locs[ref][0] * 25.4 * 1000.0
newy = locs[ref][1] * 25.4 * 1000.0
+ bc.Modify(mod)
mod.SetPosition(pcbnew.wxPoint(int(newx), int(newy)))
mod.SetOrientation(locs[ref][2]*10)
print("placing {} at {},{}".format(ref, newx, newy))
-
- pcbnew.Refresh();
+ bc.Push("place_by_sch")
+ #pcbnew.Refresh();
for my personal reference: this is my sixth patch
_______________________________________________
Mailing list: https://launchpad.net/~kicad-developers
Post to : kicad-developers@xxxxxxxxxxxxxxxxxxx
Unsubscribe : https://launchpad.net/~kicad-developers
More help : https://help.launchpad.net/ListHelp