I started using KiCad (version 4.0.1) for electronic design. It seems to be a great tool, but working with big connectors in schema editor is tedious. All connections have to be done manually and thus the process is error prone. Some way of automating the process would help. KiCad comes with scripting support, but unfortunately only in pcbnew. Eeschema seems not to have any support for automation yet. Hopefully, one can use xdotool under Linux to automate some boring tasks.

I wanted to attach the same labels to FMC connector pins as on the MicroZed FMC Carrier board – there is about 70 pins used. My initial state was this:

before.png

I copied the pin names and net labels from the original schmatic in PDF and put together the script bellow, which takes care of attaching the labels to the right pins. So after a few seconds I got the following:

after.png

The Python script that does the magic is here:

#!/usr/bin/env python3

import subprocess

conn = [
    ("LA06_P", "C10"),
    ("LA06_N", "C11"),
    ("LA10_P", "C14"),
    ("LA10_N", "C15"),
    ("LA14_P", "C18"),
    ("LA14_N", "C19"),
    ("LA18_CC_P", "C22"),
    ("LA18_CC_N", "C23"),
    ("LA27_P", "C26"),
    ("LA27_N", "C27"),

    ("LA01_CC_P", "D08"),
    ("LA01_CC_N", "D09"),
    ("LA05_P", "D11"),
    ("LA05_N", "D12"),
    ("LA09_P", "D14"),
    ("LA09_N", "D15"),
    ("LA13_P", "D17"),
    ("LA13_N", "D18"),
    ("LA17_CC_P", "D20"),
    ("LA17_CC_N", "D21"),
    ("LA23_P", "D23"),
    ("LA23_N", "D24"),
    ("LA26_P", "D26"),
    ("LA26_N", "D27"),

    ("CLK1_M2C_P", "G02"),
    ("CLK1_M2C_N", "G03"),
    ("LA00_CC_P", "G06"),
    ("LA00_CC_N", "G07"),
    ("LA03_P", "G09"),
    ("LA03_N", "G10"),
    ("LA08_P", "G12"),
    ("LA08_N", "G13"),
    ("LA12_P", "G15"),
    ("LA12_N", "G16"),
    ("LA16_P", "G18"),
    ("LA16_N", "G19"),
    ("LA20_P", "G21"),
    ("LA20_N", "G22"),
    ("LA22_P", "G24"),
    ("LA22_N", "G25"),
    ("LA25_P", "G27"),
    ("LA25_N", "G28"),
    ("LA29_P", "G30"),
    ("LA29_N", "G31"),
    ("LA31_P", "G33"),
    ("LA31_N", "G34"),
    ("LA33_P", "G36"),
    ("LA33_N", "G37"),

    ("CLK0_M2C_P", "H04"),
    ("CLK0_M2C_N", "H05"),
    ("LA02_P", "H07"),
    ("LA02_N", "H08"),
    ("LA04_P", "H10"),
    ("LA04_N", "H11"),
    ("LA07_P", "H13"),
    ("LA07_N", "H14"),
    ("LA11_P", "H16"),
    ("LA11_N", "H17"),
    ("LA15_P", "H19"),
    ("LA15_N", "H20"),
    ("LA19_P", "H22"),
    ("LA19_N", "H23"),
    ("LA21_P", "H25"),
    ("LA21_N", "H26"),
    ("LA24_P", "H28"),
    ("LA24_N", "H29"),
    ("LA28_P", "H31"),
    ("LA28_N", "H32"),
    ("LA30_P", "H34"),
    ("LA30_N", "H35"),
    ("LA32_P", "H37"),
    ("LA32_N", "H38"),
]

subprocess.call(["xdotool", "search", "--name", "/FMC/", "windowfocus"])
xtab = str.maketrans({"_": "underscore"})
for net in conn:
    label = [char.translate(xtab) for char in net[0]]
    pin = [char.translate(xtab) for char in net[1]]
    subprocess.call(["xdotool", "key", "--delay", "50", "ctrl+f"] + pin + ["Return", "Escape", "Down", "Left", "Left", "Left", "w",
                     "Left", "Left", "Left", "Left", "Left", "Left", "Left", "Left",
                     "Left", "Left", "k", "l"] + label + [ "Return", "Return"])