You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardexpand all lines: README.md
+18-15
Original file line number
Diff line number
Diff line change
@@ -12,6 +12,10 @@ This package is a pythonic wrapper around the various `pcbnew` APIs. It implemen
12
12
13
13
This package has been fully tested with KiCAD 5, 6, 7 and partially tested with 7.99.
14
14
15
+
> [!CAUTION]
16
+
> The atait fork is undergoing a refactor that will result in new package imports.
17
+
> Instances of `from kicad.pcbnew.board import Board` must be replaced by `from kigadgets.board import Board` by version 0.5.0
18
+
15
19
### An excerpt
16
20
A simple pythonic script might look like this
17
21
```python
@@ -30,10 +34,8 @@ Don't be fooled though - `track` and `board` contain no state. They use properti
30
34
31
35
1.
32
36
```
33
-
git clone git@github.com:atait/kicad-python
34
-
pip install kicad-python/.
37
+
pip install kigadgets
35
38
```
36
-
<!-- pip install kigadgets -->
37
39
38
40
2. Open the pcbnew GUI application. Open its terminal  or  and run these commands in kicad 6+
39
41
```python
@@ -105,9 +107,7 @@ Third, it exposes KiCad's `pcbnew.py` to your external python environment. The p
105
107
**Effect:** You can now use the full KiCad built-in SWIG wrapper, the `kicad-python` package, and any non-GUI plugins you are developing *outside of the pcbnew application*. It is useful for batch processing, remote computers, procedural layout, continuous integration, and use in other software such as FreeCAD and various autorouters.
106
108
107
109
## Snippet examples
108
-
These snippets are run in the GUI terminal. They are common automations that don't need dedicated action plugins
109
-
110
-
There is no preceding context; the linking step above provides `pcb` to the terminal. These all should work in pcbnew 5, 6, or 7 on Mac, Windows, or Linux.
110
+
These snippets are run in the GUI terminal. They are common automations that aren't worth making dedicated action plugins. There is no preceding context; the linking step above provides `pcb` to the terminal. These all should work in pcbnew 5, 6, or 7 on Mac, Windows, or Linux.
111
111
112
112
### Hide silkscreen labels of selected footprints
113
113
```python
@@ -131,6 +131,7 @@ pcbnew.Refresh()
131
131
```
132
132
133
133
### Select similar vias
134
+
This snippet assumes you have selected one via
134
135
```python
135
136
og_via =next(pcb.selected_items)
136
137
for via2 in pcb.vias:
@@ -140,7 +141,9 @@ for via2 in pcb.vias:
140
141
og_via.select(False)
141
142
pcbnew.Refresh()
142
143
```
143
-
There is some additional functionality for micro and blind vias.
144
+
The function `next` is used because `pcb.items` is a generator, not a list. Turn it into a list using the `list` function if desired.
145
+
146
+
See `via.py` for additional functionality related to micro and blind vias.
144
147
145
148
### Change all drill diameters
146
149
Because planning ahead doesn't always work
@@ -170,7 +173,7 @@ for mod in pcb.footprints:
170
173
mod.select()
171
174
```
172
175
173
-
### Import user library
176
+
### Import user library for GUI/CLI
174
177
Suppose you wrote a file located in $KICAD_SCRIPTING_DIR/my_lib.py
`kicad-python`is a stateless wrapper of objects, not just an API wrapper. It stays synchronized with the state of the underlying native objects even when they are modified elsewhere.
212
+
`kicad-python` stays synchronized with the state of the underlying native objects even when they are modified elsewhere because it is wrapping the C++ state rather than holding a Python state.
210
213
211
214
### Procedural layout
212
215
Suppose you want to test various track width resistances.
@@ -224,7 +227,7 @@ for w in widths:
224
227
y +=20
225
228
pcbnew.Refresh()
226
229
```
227
-
Go ahead and try this out in the pcbnew terminal, although this type of thing is better to stick in a user library(see above). The sky is the limit when it comes to procedural layout!
230
+
Go ahead and try this out in the pcbnew terminal, although this type of thing is better to stick in a user library(see above). The sky is the limit when it comes to procedural layout!
228
231
229
232
## Related packages
230
233
KiCAD has a rich landscape of user-developed tools, libraries, and plugins. They have complementary approaches that are optimized for different use cases. It is worth understanding this landscape in order to use the right tool for the job. This is how `kicad-python` fits in.
@@ -236,13 +239,13 @@ KiCAD has a rich landscape of user-developed tools, libraries, and plugins. They
| Documentation | extensive | "documents itself" for now|
244
247
245
-
**Audiences:** While `KiKit` is directed primarily to end users, `kicad-python` is directed moreso to developers and coders. It is lean: <2,800 lines of code, no constraints on python version, and **zero dependencies** besides `pcbnew.py`. Out of the box, `kicad-python` offers very little to the end user who doesn't want to code. It has no entry points, meaning the user must do some coding to write 10-line snippets, action plugins, and/or batch entry points. In contrast, out of the box, `KiKit` exposes highly-configurable, advanced functionality through friendly entry points in CLI and GUI action plugins.
248
+
**Audiences:** While `KiKit` is directed primarily to end users, `kicad-python` is directed moreso to developers and coders. It is lean: <2,800 lines of code, no constraints on python version, and **zero dependencies** besides `pcbnew.py`. Out of the box, `kicad-python` offers very little to the end user who doesn't want to code. It has no entry points, meaning the user must do some coding to write 10-line snippets, action plugins, and/or batch entry points. In contrast, `KiKit` comes with batteries included. It exposes highly-configurable, advanced functionality through friendly entry points in CLI and GUI action plugins.
246
249
247
250
**Internals:**`KiKit` performs a significant amount of internal state handling and CAD logic (via `shapely`). `kicad-python` does not store state; it is a thin wrapper around corresponding SWIG objects. While the first approach gives functionality beyond `pcbnew` built into KiKit, the second exposes the key functionality of underlying objects, leaving the state and logic to C++. It requires a coder to do things with those objects. If that dev wants to use `shapely` too, they are welcome to import it.
0 commit comments