Text Variables do not update when set from plugin
Description
The pcbnew BOARD
class has both GetProperties and SetProperties methods for getting/setting Text Variables. As described in this forum post however, the SetProperties method only modifies the *.kicad_pcb
file, not the *.kicad_pro
file. This means that despite the fact that text elements that contain the variable update to the variable value when calling the method, saving the PCB in KiCad overwrites any changes made to the *.kicad_pcb
file and restores the template text.
Steps to reproduce
Example plugin that is supposed to create a text variable called "MY_VARIABLE" when clicking the "click me" button in the toolbar:
exampleplugin.zip
- Create a plugin that modifies board properties and then uses SetProperties to update the board:
board = pcbnew.GetBoard() properties = board.GetProperties() properties['MY_VARIABLE'] = "I am a text variable!" board.SetProperties(properties)
- Open KiCad PCB Editor
- Create a text element with the contents
${MY_VARIABLE}
- Run the plugin (e.g. through a toolbar button)
- Observe that the text element updates to
I am a text variable!
- Observe that the variable is not present in Board Setup -> Text Variables
- Save the project and see the text element revert to
${MY_VARIABLE}
KiCad Version
Application: KiCad x64 on x64
Version: 7.0.9, release build
Libraries:
wxWidgets 3.2.3
FreeType 2.12.1
HarfBuzz 8.2.1
FontConfig 2.14.2
libcurl/8.4.0-DEV Schannel zlib/1.3
Platform: Windows 11 (build 22621), 64-bit edition, 64 bit, Little endian, wxMSW
Build Info:
Date: Nov 5 2023 19:26:40
wxWidgets: 3.2.3 (wchar_t,wx containers)
Boost: 1.83.0
OCC: 7.7.1
Curl: 8.4.0-DEV
ngspice: 41
Compiler: Visual C++ 1936 without C++ ABI
Build settings:
KICAD_SPICE=ON