From 1a7bcaebf60aef52ab2a474fad6f06f3053e3ada Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jan=20Mr=C3=A1zek?= Date: Tue, 17 Oct 2023 07:16:10 +0200 Subject: [PATCH] Add support for project variables in texts --- docs/panelization/cli.md | 10 ++++++---- kikit/text.py | 3 +++ 2 files changed, 9 insertions(+), 4 deletions(-) diff --git a/docs/panelization/cli.md b/docs/panelization/cli.md index 2f6be3bb..3de1d8b6 100644 --- a/docs/panelization/cli.md +++ b/docs/panelization/cli.md @@ -450,10 +450,12 @@ Fiducials based on a plugin. Add text to the panel. Allows you to put a single block of text on panel. You can use variables enclosed in `{}`. E.g. `{boardTitle} | {boardDate}`. The list -of all available variables in listed bellow. In the case you need more -independent texts on the panel, you can use sections names `text2`, `text3` and -`text3` to add at most 4 text. All these sections behave the same and accept the -same options. +of all available variables in listed bellow. You can also use the variables +specified in the project. They are prefixed with `user-`. That is, to include +your variable `revision` in KiKit text, use formatting string `Rev: +{user-revision}`. In the case you need more independent texts on the panel, you +can use sections names `text2`, `text3` and `text3` to add at most 4 text. All +these sections behave the same and accept the same options. If you need more texts or more sophisticated placing options, see `script` option from `postprocess`. diff --git a/kikit/text.py b/kikit/text.py index 76fbd16e..5d3f5b5f 100644 --- a/kikit/text.py +++ b/kikit/text.py @@ -43,4 +43,7 @@ def kikitTextVars(board: pcbnew.BOARD, vars: Dict[str, str]={}) -> Dict[str, Any for i in range(10): availableVars[f"boardComment{i + 1}"] = Formatter(lambda: board.GetTitleBlock().GetComment(i), vars) + for var, value in vars.items(): + availableVars[f"user-{var}"] = value + return availableVars