Hello, I’m new to the Python Scripting Console, apologies if I’m doing something wrong. A lot of tutorials/blog examples on Python Scripting on the Internet don’t work so I’ve had to experiment a bit. I’m using KiCAD 6.0.0 on Windows 11.
I start with a blank PCB project, and place the silkscreen text ‘abc’ using the normal Add Text icon, i.e. not using Python. Then, using the Scripting Console, I tried to read that text in Python, and to also create new text ‘hello’.
The commands I used are listed below. At the end of that, the text ‘hello’ is not visible, but it is there, because if I click at the location where I expect to see it, it appears, and the properties box looks good too, but as soon as I close the properties box the text disappears again. I suspect I have not configured an attribute or two, but I don’t know what. Any help would be greatly appreciated. I have attached a screenshot of what I see, the text ‘hello’ is visible because I clicked where it should be, but it will disappear when I close the properties box).
import pcbnew pcb=pcbnew.BOARD() board = pcbnew.GetBoard() gd=board.GetDrawings() print(gd) [<pcbnew.PCB_TEXT; proxy of <Swig Object of type 'PCB_TEXT *' at 0x000001D0D0DD9210> >] pcbnew.PCB_TEXT.GetX(gd) 0 pcbnew.PCB_TEXT.GetY(gd) 0 pcbnew.PCB_TEXT.GetText(gd) 'abc' pcbnew.PCB_TEXT.GetBoundingBox(gd) <pcbnew.EDA_RECT; proxy of <Swig Object of type 'EDA_RECT *' at 0x000001D0D0DD9060> > pcbnew.PCB_TEXT.GetClass(gd) 'PTEXT' pcbnew.PCB_TEXT.SetItalic(gd, True) sz = pcbnew.PCB_TEXT.GetTextSize(gd) sz wxSize(10000000, 10000000) t2=pcbnew.PCB_TEXT(board) t2.SetText('hello') t2.SetTextX(0) t2.SetTextY(0) t2.SetVisible(True) t2.SetTextSize(sz) board.Add(t2) gd=board.GetDrawings() print(gd) [<pcbnew.PCB_TEXT; proxy of <Swig Object of type 'PCB_TEXT *' at 0x000001D0D0DD9510> >, <pcbnew.PCB_TEXT; proxy of <Swig Object of type 'PCB_TEXT *' at 0x000001D0D0DD9360> >] pcbnew.PCB_TEXT.GetText(gd) 'hello' pcbnew.PCB_TEXT.GetText(gd) 'abc' pcbnew.PCB_TEXT.GetLayer(gd) 37 pcbnew.PCB_TEXT.GetEffectiveTextPenWidth(gd) 150000 pcbnew.PCB_TEXT.SetLayer(gd, 37)