Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
script to generate KiCad footprint for Panasonic JW2 relay
#!/usr/bin/env python3
import sys
sys.path.append("/Users/ppelleti/src/kicad-footprint-generator")
from KicadModTree import *
footprint_name = "Relay_DPDT_Panasonic_JW2"
f = Footprint(footprint_name)
f.setDescription("Panasonic Relay DPDT, http://www3.panasonic.biz/ac/e_download/control/relay/power/catalog/mech_eng_jw.pdf?via=ok")
f.setTags("Panasonic Relay DPDT")
f.append(Model(filename="${KISYS3DMOD}/Relays_THT.3dshapes/" +
footprint_name + ".wrl",
at=[0.0, 0.0, 0.0],
scale=[1.0, 1.0, 1.0],
rotate=[0.0, 0.0, 0.0]))
d = [1.5, 1.5]
p = [2.5, 2.5]
s = [1.0, 1.0]
t = 0.15
wCrtYd = 0.05
wFab = 0.1
wSilkS = 0.12
crtYd = 0.5
xPadLeft = 0.0
xPadRight = 7.5
yPad18 = 0.0
yPad27 = 15.0
yPad36 = 20.0
yPad45 = 25.0
xMiddle = (xPadLeft + xPadRight) / 2
xLeft = xMiddle - 6.4
xRight = xMiddle + 6.4
xLeftCrtYd = xLeft - crtYd
xRightCrtYd = xRight + crtYd
yBottom = yPad45 + 1.3
yTop = yBottom - 28.6
yTopCrtYd = yTop - crtYd
yBottomCrtYd = yBottom + crtYd
yRefSilk = yTop - 1
yRefFab = (yTop + yBottom) / 2
yValue = 27.94
xLeftCoil = xMiddle - 0.35
xRightCoil = xMiddle + 0.35
yTopCoil = -0.6
yBottomCoil = 0.6
yTopSlash = -0.2
yBottomSlash = 0.2
xLeftLine = xPadLeft + 1.5
xRightLine = xPadRight - 1.5
indSpace = wFab + 2 * wSilkS
indLen = 2
pin1Indicator = [[xLeft - indSpace, yTop + indLen],
[xLeft - indSpace, yTop - indSpace],
[xLeft + indLen, yTop - indSpace]]
# Text
f.append(Text(type="reference", text="REF**",
at=[xMiddle, yRefSilk], layer="F.SilkS", size=s, thickness=t))
f.append(Text(type="value", text=footprint_name,
at=[xMiddle, yValue], layer="F.Fab", size=s, thickness=t))
f.append(Text(type="user", text="%R",
at=[xMiddle, yRefFab], layer="F.Fab", size=s, thickness=t))
# Fab
f.append(RectLine(start=[xRight, yBottom],
end=[xLeft, yTop],
layer="F.Fab", width=wFab))
f.append(Line(start=[xLeftLine, yPad18],
end=[xRightLine, yPad18],
layer="F.Fab", width=wFab))
f.append(PolygoneLine(polygone=pin1Indicator, layer="F.Fab", width=wFab))
# Silk
f.append(RectLine(start=[xRight + wFab, yBottom + wFab],
end=[xLeft - wFab, yTop - wFab],
layer="F.SilkS", width=wSilkS))
f.append(Line(start=[xLeftCoil, yBottomSlash],
end=[xRightCoil, yTopSlash],
layer="F.SilkS", width=wSilkS))
f.append(RectLine(start=[xRightCoil, yBottomCoil],
end=[xLeftCoil, yTopCoil],
layer="F.SilkS", width=wSilkS))
f.append(PolygoneLine(polygone=pin1Indicator, layer="F.SilkS", width=wSilkS))
# Courtyard
f.append(RectLine(start=[xRightCrtYd, yBottomCrtYd],
end=[xLeftCrtYd, yTopCrtYd],
layer="F.CrtYd", width=wCrtYd))
# Pads
f.append(Pad(number="1", type=Pad.TYPE_THT, shape=Pad.SHAPE_RECT,
at=[xPadLeft, yPad18], size=p, layers=Pad.LAYERS_THT, drill=d))
f.append(Pad(number="2", type=Pad.TYPE_THT, shape=Pad.SHAPE_OVAL,
at=[xPadLeft, yPad27], size=p, layers=Pad.LAYERS_THT, drill=d))
f.append(Pad(number="3", type=Pad.TYPE_THT, shape=Pad.SHAPE_OVAL,
at=[xPadLeft, yPad36], size=p, layers=Pad.LAYERS_THT, drill=d))
f.append(Pad(number="4", type=Pad.TYPE_THT, shape=Pad.SHAPE_OVAL,
at=[xPadLeft, yPad45], size=p, layers=Pad.LAYERS_THT, drill=d))
f.append(Pad(number="5", type=Pad.TYPE_THT, shape=Pad.SHAPE_OVAL,
at=[xPadRight, yPad45], size=p, layers=Pad.LAYERS_THT, drill=d))
f.append(Pad(number="6", type=Pad.TYPE_THT, shape=Pad.SHAPE_OVAL,
at=[xPadRight, yPad36], size=p, layers=Pad.LAYERS_THT, drill=d))
f.append(Pad(number="7", type=Pad.TYPE_THT, shape=Pad.SHAPE_OVAL,
at=[xPadRight, yPad27], size=p, layers=Pad.LAYERS_THT, drill=d))
f.append(Pad(number="8", type=Pad.TYPE_THT, shape=Pad.SHAPE_OVAL,
at=[xPadRight, yPad18], size=p, layers=Pad.LAYERS_THT, drill=d))
file_handler = KicadFileHandler(f)
file_handler.writeFile(footprint_name + ".kicad_mod")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment