Created
April 10, 2022 18:04
-
-
Save mcbridejc/abeeb7976d6d89cd2c0c80fd3a1ab94f to your computer and use it in GitHub Desktop.
How to group KiCad tracks created in python
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
""" | |
When creating a lot of board features (tracks, vias, etc) from a python script, | |
grouping them allows them to be easily selected together in pcbnew. This can be | |
useful if, for exampe, you want to move them together after generating, or if | |
you find yourself iterating and need to delete the old tracks each time before | |
re-running the script. | |
Luckily, it's easy to create a group and assign it to elements as they are | |
created in python; here's a quick example. | |
""" | |
import pcbnew | |
def pcbpoint(p): | |
return pcbnew.wxPointMM(float(p[0]), float(p[1])) | |
# Get the board. This assume you are running in pcbnew with a board already | |
# open. It's also possible to use LoadBoard to open a .kicad_pcb file. | |
board = pcbnew.GetBoard() | |
# Create a new group, and add it to the board | |
group = pcbnew.PCB_GROUP(board) | |
board.Add(group) | |
# Create a new element, and add it to the group (as well as the board) | |
track = pcbnew.PCB_TRACK(board) | |
track.SetStart(pcbnew.wxPointMM(100, 100)) | |
track.SetEnd(pcbnew.wxPointMM(100, 110)) | |
track.SetWidth(int(0.2 * 1e6)) | |
track.SetLayer(pcbnew.F_Cu) | |
board.Add(track) | |
group.AddItem(track) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment