Hallo Forum,
I’m new to python scripting in KiCad. I was trying to make all references in a board invisible. In contrast, all values should be visible and on the “front silk screen layer”.
The script, I wrote for that (see below) as two problems:
a) Nothing I change seems to take effect in PCBNew
b) I get an exception on setting the visibilty (solved!)
Traceback (most recent call last):
File "<input>", line 1, in <module>
File "/home/confus/sync/prog/kicad/espdev/scripttest/refval.py", line 21, in <module>
val.SetVisible(1)
File "/usr/lib/python2.7/dist-packages/pcbnew.py", line 2697, in SetVisible
return _pcbnew.EDA_TEXT_SetVisible(self, aVisible)
TypeError: in method 'EDA_TEXT_SetVisible', argument 2 of type 'bool'
I have now idea, why. I run my script from within the scripting console using the command execfile('/home/confus/sync/prog/kicad/espdev/scripttest/refval.py')
. Of course I have my layout open in PCBNew and run the console from the same window.
Here is the content of my script file:
from __future__ import print_function
from pcbnew import *
pcb = GetBoard()
mods = pcb.m_Modules
for mod in mods:
print(mod.GetReference(), mod.GetValue())
val = mod.Value()
val.SetLayer(37) # Layer 37 = F.SilkS
try:
val.SetVisible(1)
mod.Reference().SetVisible(0)
except Exception, e:
print(e)
pass
print('Done.')
And here is the version information for my dev-build of KiCad4:
What am I doing wrong?