How do I script the placement of specific components at exact locations on a KiCad PCB using Python?
To script the placement of specific components at precise locations on a KiCad PCB using Python, you can use the pcbnew module to find and position these components. The example script shows how to position 'R1', 'R2', and 'D1' at specific coordinates:

```python
import pcbnew
from pcbnew import wxPoint, wxPointMM

board = pcbnew.GetBoard()
r1 = board.FindFootprintByReference('R1')
r2 = board.FindFootprintByReference('R2')
d1 = board.FindFootprintByReference('D1')
assert(r1 and r2 and d1)

r1.SetPosition(wxPointMM(20, 20))    # Place R1 at (20, 20) mm
r2.SetPosition(wxPointMM(25, 21))    # Place R2 at (25, 21) mm
d1.SetPosition(wxPointMM(23, 26))    # Place D1 at (23, 26) mm

pcbnew.Refresh()
```

This script is practical for precision placement of components, which is essential in complex PCB designs where exact component positioning is crucial.