New string replacement options for kicad assets

Text variables are in. They are defined per project and can be used in fields, schematic and board text, output paths, etc.

Referenced as you might expect: ${var-name}.

The existing % escapes (worksheet fields, %R and %V, etc.) were also moved to the new architecture. So, for instance ${VALUE} now gets you the symbol’s value. The set of system variables was also expanded.

System variables for symbol text:
REFERENCE
VALUE
FOOTPRINT
FOOTPRINT_LIBRARY
FOOTPRINT_NAME
DATASHEET
UNIT
user-defined fields by name

System variables for sheet text:
SHEETNAME
SHEETFILENAME
user-defined fields by name

System variables for module text:
REFERENCE
VALUE
LAYER

System variables for PCB text:
LAYER

System variables for worksheet text:
KICAD_VERSION
# (sheet number)
## (sheet count)
SHEETNAME
FILENAME
PAPER
LAYER
ISSUE_DATE
REVISION
TITLE
COMPANY
COMMENT0, COMMENT1COMMENT9

5 Likes

Does this imply we can now do math in say schematic comments? e.g. “${R2:VALUE} * 5.01 / ${R7:VALUE}”

If not, I know its a weird request, but its been something I have been hoping for, to automate some of the math during designing,

See also my wishes in https://gitlab.com/kicad/code/kicad/-/merge_requests/143#note_317705021.

1 Like

No, we don’t currently support evaluation in text. (We do in many dialogs.)

Oops, forgot one: in the context of labels, CONNECTION_TYPE will return the electrical type.

Does the old %R still work? Otherwise the whole official lib does no longer work with nightly until v6 development starts.

Based on the discussion here I would say existing systems is untouched and works as before.

BTW, this could be moved to a new thread. There will certainly be more details, maybe the feature needs some instructions etc.

%R no longer works, but %R will get converted to ${REFERENCE} when the file is read in.

I think I only tested this on schematics though. Someone should probably verify that it works when loading symbols…

This explains why duplicated values generated by my Altium importer no longer work ^^

What happens if the user opens a footprint in a read only lib (which the official lib is).

Conversion is done in memory. (Since the conversion is deterministic it doesn’t bother to set the modified flag – reading it a second time will just convert it again.)

So a read-only lib isn’t an issue: it will just get converted every time it’s read.

Ha! Yes, it would indeed. Sorry about that. :flushed:

I pushed a fix: https://gitlab.com/kicad/code/kicad/-/merge_requests/151

For comparison: those are the special strings supported by altium:

https://www.altium.com/documentation/altium-designer/pcb-obj-stringstring-ad?version=19.1#!pcb-predefined-special-strings

Interesting. I wonder if all those counts are used much?

Closed source software like Altium that has evolved for many years, will have more unexplained legacy fragments that nobody dares touch than any opensource project. It’s just the way things are when the code is not meant to be shared and then a key person quits.

Something that would be nice, at least for my work flow, is at the PCB level having access to the schematic version in addition to the PCB version. I like to have both version on my board so later when I grab a board I can see what version of the schematic was used for that version of the PCB. (Schematic versions tend to go faster than PCB versions.)

1 Like

It’s probably also that Open Source developers don’t do it for profit, so there’s no need to focus on only profitable new features. Some people like to refactor for quality because it feels good or does good for the project.

One reason, with the addition that the “many eyes” really does help when enough developers from around the world with diverse backgrounds work on a project like KiCad. Commercial software rarely has this range of competencies available.
Another one is that big EDA packages like Altium have inherited code from companies that have been taken over and merged in a rush

@JeffYoung, I can open the Text Variables grid but can’t add items there. In the video I’m trying to click on the button. Nothing happens. This is on Windows, I think I experienced the same on Linux.

(EDIT: That was a bug which has now been fixed.)

@eelik, that doesn’t reproduce for me on OSX. Anyone else seeing that?