Hi,
A task I’m finding I’m doing repeatedly is reformatting the text size for reference and value since I’m using a lot of libraries I’ve found online. I’ve made a simple script to get a uniform starting point. Hope it’s helpful for others.
#!/usr/bin/env python
from pcbnew import *
pcb = GetBoard()
moduleCount = 0
for aModule in pcb.GetModules():
aModule.Reference().SetVisible(1)
aModule.Reference().SetHeight(1000000)
aModule.Reference().SetWidth(1000000)
aModule.Value().SetVisible(1)
aModule.Value().SetHeight(800000)
aModule.Value().SetWidth(800000)
moduleCount = moduleCount + 1
mc_str = str(moduleCount)
print('TextFormat script updated the text of '+mc_str+' Modules.')
print('[Board: '+pcb.GetFileName()+']')
TextFormat.py (505 Bytes)
It’s also attached here as a file. The version here sets the reference text to 1x1mm, the values to 0.8x0.8mm and both visible. It only changes text on modules, so any text elements you’ve added to the board won’t be changed.
To bend it to your preference, height and width are set as 1mm = 1,000,000 in the height or width function; to make either text item invisible, change the 1 to a 0.
Save your edited file in the KiCad script directory. On my Windows installation that’s …/kicad/bin/scripting/plugins.
To use it in KiCad, with your board open in pcbnew open the python scripting console (Tools/Scripting Console). After the >>> prompt appears, type import TextFormat. When you press enter, it will run on the currently open board design.
Once you’ve imported it, to invoke the script the next and subsequent times you need it, jump into the console and use the command reload(TextFormat)
Cheers! Geoff