How can I script custom PCB contours based on the locations of specific components in KiCad?
Scripting custom PCB contours based on component locations in KiCad can be done using Python. The provided script demonstrates this by drawing lines on the Edge_Cuts layer to form a contour around selected components:

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

def add_line(start, end, layer=pcbnew.Edge_Cuts):
    board = pcbnew.GetBoard()
    segment = pcbnew.PCB_SHAPE(board)
    segment.SetShape(pcbnew.SHAPE_T_SEGMENT)
    segment.SetStart(start)
    segment.SetEnd(end)
    segment.SetLayer(layer)
    segment.SetWidth(int(0.1 * pcbnew.IU_PER_MM))
    board.Add(segment)

# Script to define start and end points for custom contour
# ... (rest of the script)
add_line(start, end)

pcbnew.Refresh()
```

This script is ideal for designing PCBs with unique shapes or for fitting PCBs into specific enclosures or spaces.