How can I script the addition of a via and a connecting track near a specific pad in KiCad using Python?
Scripting the addition of a via and a connecting track near a specific pad in KiCad can be done using Python. The provided script demonstrates this by adding a via and a track near pad #2 of footprint 'R2':

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

board = pcbnew.GetBoard()
pad = board.FindFootprintByReference('R2').FindPadByNumber('2').GetCenter()
via_location = wxPoint(pad.x + 1 * pcbnew.IU_PER_MM, pad.y)
add_track(pad, via_location)
via = pcbnew.PCB_VIA(board)
via.SetPosition(via_location)
via.SetDrill(int(0.4 * 1e6))
via.SetWidth(int(0.8 * 1e6))
board.Add(via)

pcbnew.Refresh()
```

This script is effective for creating vias and tracks for electrical connections or thermal management in specific areas of a PCB layout.