KiCad 6 Text Variables with Python scripts

Hi,
I discorver Text Variables in pcbnew in Kicad6 and i want to use this feature with python script.
Is it possible? and how?
I want to create new variables or read them if they are présent.
I have open may pcb file with a text editor and i found this text variables location :
(property “ModuleRef” “7442030SO”)

You can get them using GetProperties() of the board object but if you try to change them they will be lost. Their purpose is to use them in text fields on pcb.

Thank you for your quick answer.
I can change them but as you say, when I restart Pcbnew my changes are lost.
I discovered that these variables are also stored at the end of the *.kicad_pro file.
“text_variables” : {
“ModuleRef” : “7442030SO”
}

I tried this:
var = board.GetProperties()
var[‘ModuleRef’] = “test value”.
board.SetProperties(var)

This only changes the value in the *.kicad_pcb but not in the *.kicad_pro. I think this is the reason why the value is reset.
Is it possible to create new variables by script? I am a novice in Python ^^.

I’ve wrote my own pick and place export function to générate files that are directly usable on Europlacer’s machines.
I want to use these variables to store some strings (file reference number and file name) when I close my plugin’s dialog window without using a *.ini file.
I think this is a smart idea. It would be nice if they stayed stored when I close pcbnew, but that’s not really important.

That’s right.

If you are running your script standalone (not as pcbnew action plugin) then you can just open kicad_pro and modify it, it’s json. Otherwise separate config file is the way to go.

@qu1ck , is this issue a valid one: PythonApi: Expose ExpandTextVars kicad_pcb - vise (#10015) · Issues · KiCad / KiCad Source Code / kicad · GitLab ? (Or am I missing something…)

It’s somewhat related but in this thread we are discussing writing to the variables (and reading them back).

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.