This seems like the appropriate place to document progress on my python pads script. It’s not ready for deployment, but I wanted to share some capabilities I’m developing. Here are the comments in the code I shared on the Developer’s list. I haven’t posted the code anywhere yet, but I’d be glad to share snippets of code if you’re interested, just ask! My intent is to donate to the KiCAD project when I get it to conform to the style guidelines and fix some of the shortcomings (pad shapes, and front/back pads, in particular).
I also have decent references to drill sizes, and stencil rules of thumb (vs. aperture ratios, solder powder size/type).
If you are aware of other tools (including built-in KiCAD tools) that do the same tasks or similar, please let me know.
I’ve already begun fixing some of the bugs listed below (integrating via and pad holes, starting to recognize holes on multiple layers, fixing some of the unit conversions to pcbnew.IU_PER_MM and IU_PER_MILS) and will continue development.
I like the name “KiPad”. Is that indicative of what this script does? Is that name taken already?
# PadDrillStencilSilk.py
# Original Author: Greg Smith, June 2017
#
# ABOUT:
# This python script provides additional basic DRC checks to KiCAD
# and lists to make tweaking pads for stencil creation.
# It adds a menu item to "Tools" called Pads/Vias/Stencils.
#
# This is VERY beta. Not thoroughly tested. Not well commented.
#
# Not conforming to style guides (neither Python nor KiCAD style guides).
# Inputs and outputs are in varying non-changable units (mils, inches, mm, nm)
# Only tested on KiCAD 4.06, Windows 7.
#
# Install: place file in C:\Program Files\KiCad\share\kicad\scripting\plugins\PadDrillStencilSilk.py
# in pcbnew, open scripting console (Tools > Scripting Console)
# type "import PadDrillStencilSilk"
#
# THERE ARE BUGS:
#
# Only handles 2-layer boards, only through vias, and pads are not verified for shape.
# Does not check pad drill DRC
# Assumes all pads are on the front.
# Does not mix via drill and pad drill checks.
# Does not check annular ring size.
#
# Pad Info: Produces two lists:
# 1) detailed list of pads by footprint reference with paste/mask properties
# 2) quantity of pads by size
# Drill Info: Generates multiple lists:
# 1) Hole quantity by specified pad drill sizes
# 2) Quantity by closest larger standard drill size (future option to pick drill sets)
# 3) Drill list
# 4) Distance from each via to next closest via
# 5) Checks via drill to via drill clearance
# 6) Checks via drill to track clearance
# Stencil Info:
# 1) Lists quantity of apertures by aperture size
# 2) Summary of aperture ratios by stencil thickness
# 3) Checks AspectRatio and AreaRatio against a variety
# of stencil thicknesses (2 mil-7 mil, all currently hardcoded)
#
# EXAMPLES:
#
# Pad Info: Produces two lists:
# 1) detailed list of pads by footprint reference with paste/mask properties
# Number of pads: 293
#
# ***** Pads By Footprint Reference, Alphabetical *****
# # 4 (BT1.) X=113.665086 Y=147.423648 P=CIRC (2.64, 2.64) D=CIRC
# (2.64, 2.64) Layers=F.Cu,B.Cu,B.Mask,F.Mask lc=0.0000 c=0.1530
# Paste: spm=0.0000,0.0000 lspm=0.0000 lspmr=0.0000 | Mask : smm=0.0000 lsmm=0.0000
# ...
# 2) quantity of pads by size
# ***** Quantity of Pads By Size *****
# Size: 0.900 0.900, Quantity 4
# Size: 0.875 1.250, Quantity 2
# Size: 0.800 1.200, Quantity 2
# Size: 0.900 1.700, Quantity 1
# Size: 0.300 0.800, Quantity 24
# ...
#
# Drill Info: Generates multiple lists:
# 1) Hole quantity by specified pad drill sizes
# ***** Quantity of Pads By Specified Drill Size *****
# Size: 1.020mm, Quantity 2
# Size: 4.826mm, Quantity 6
# Size: 1.000mm, Quantity 54
# Size: 2.640mm, Quantity 2
# Size: 1.097mm, Quantity 8
#
# 2) Hole quantity by closest larger standard drill size (future option to pick drill sets)
# ***** Quantity of Pads By Standard Drill Size *****
# Size: 1.020mm (25.908 mils), Drill: 0.041 (59), Quantity 2
# Size: 4.826mm (122.580 mils), Drill: 0.191 (11), Quantity 6
# Size: 1.000mm (25.400 mils), Drill: 0.04 (60), Quantity 54
# Size: 2.640mm (67.056 mils), Drill: 0.104 (37), Quantity 2
# Size: 1.097mm (27.871 mils), Drill: 0.0465 (56), Quantity 8
#
# 3) Drill list
# ***** Drill Holes List (pad #, position (nm), Type, Drill, Drill Value, Via Width) *****
# 0 (152661291, 138048648) 3 294000 294000 600000
# 1 (113725000, 140800000) 3 294000 294000 600000
# ...
#
# 4) Distance from each via to next closest via
# ***** Distance to next closest via ***** (looking only *forward* through the list)
#
# Minimum Via to Via = 20.000 mils (0.508 mm)
# 0 3.692 mm
# 1 1.205 mm
# ...
#
# 5) Checks via drill to via drill clearance
# ***** Vias too close to another via *****
# 29
# 44
# ...
# 6) Checks via drill to track clearance
# ***** Vias too close to track *****
# 31 Via (/IOC_RB6) at (125934690, 138137006) is 306005 away from track (/IOC_RB5)
# ((126280790, 137531001) ; (125660499, 137531001)). Shoud be 508000
# 23 Via (/GND) at (150540086, 141423648) is 307472 away from track (/RE2)
# ((149487558, 140816176) ; (152110941, 140816176)). Shoud be 508000
# ...
#
#
# Stencil Info:
# 1) Lists quantity of apertures by aperture size:
# (Aperture size in mm, triplets of stencil mil thickness, area ratio, aspect ratio)
# (qty 24) Aperture=0.225,0.725 (2.0 1.69 4.43) (3.0 1.13 2.95) (4.0 0.85 2.21)
# (5.0 0.68 1.77) (6.0 0.56 1.48) (7.0 0.48 1.27)
# Pads: [20, 45, 80, 98, 99, 100, 101, 109, 113, 121, 125, 140, 143, 165,
# 205, 208, 209, 210, 233, 234, 238, 239, 241, 244]
# From: CONN_01X24
# ...
#
# 2) Summary of aperture ratios by stencil thickness
# ***** Aperture Ratio Ranges *****
# 2.0 mil Aspect: 4.429 14.764 Area : 1.471 4.318
# 3.0 mil Aspect: 2.953 9.843 Area : 0.981 2.879
# 4.0 mil Aspect: 2.215 7.382 Area : 0.735 2.159
# 5.0 mil Aspect: 1.772 5.906 Area : 0.588 1.727
# 6.0 mil Aspect: 1.476 4.921 Area : 0.490 1.439
# 7.0 mil Aspect: 1.265 4.218 Area : 0.420 1.234
#
# 3) Checks AspectRatio and AreaRatio against a variety
# of stencil thicknesses (2 mil-7 mil, all currently hardcoded):
# ***** Failed Aperture Test *****
# Failed 5.0 mil thickness:
# Failed Area : 0.445 0.225
# Failed Area : 0.300 0.350
# Failed 6.0 mil thickness:
# Failed Area : 0.555 0.245
# Failed Area : 0.445 0.225
# Failed Area : 0.300 0.350
# Failed Area : 0.225 0.725
# Failed Aspect: 0.445 0.225
# Failed Aspect: 0.225 0.725
# Failed 7.0 mil thickness:
# Failed Area : 0.555 0.245
# Failed Area : 0.325 0.725
# Failed Area : 0.445 0.225
# Failed Area : 0.300 0.350
# Failed Area : 0.225 0.725
# Failed Aspect: 0.555 0.245
# Failed Aspect: 0.445 0.225
# Failed Aspect: 0.225 0.725
#
#
# Nevertheless, there are some examples of using python code to interact with KiCAD:
# Install Tools menu, replace if already existing (allows reloading python file after changes)
# Iterate over tracks, identify vias, get sizes of via copper, mask, and paste
# Identify which layers a pad is on.
# Generate basic interactive window.
# Display multi-threaded wx.Gauge (progress bar)
# Get Paste (stencil) Aperture size calculated from pad properties.
# TODO list, aside from fixing the BUGS above.
# Support front and back layers.
# Support more than just through drills (i.e. buried/blind vias)
# Label units and make consistent. Use KiCAD-provided "native unit" conversion
# Mask Info: Checks solder mask dam sizes.
# Silk Info: Checks silk screen character sizes.
#
Greg S.