Clone
2
variables
ispyisail edited this page 2026-09-14 20:36:22 +12:00

Variables and formulas

Several fields in QElectroTech accept a formula — text with % variables that QET substitutes when it draws. %f-%l%c on an element label becomes 3-B7. %id/%total in the folio field becomes 3/12.

The catch is that there is no single variable language. Five different places accept formulas, each resolves a different set, and a variable that works in one is silently left as literal text in another. That is what this page is for.

Sources: sources/autoNum/assignvariables.cpp (AssignVariables, replaceVariable), sources/bordertitleblock.cpp, sources/titleblocktemplate.cpp (interpreteVariables).


1. Where formulas are accepted

Where Set in Resolves
Element label element information, or Project properties → element auto-numbering position, folio, sequences, %{…} info
Conductor text conductor properties → formula, or conductor auto-numbering position, folio, sequences, wire properties
Folio field folio properties → Folio only %autonum, %id, %total
Title block cells the .titleblock template whatever is in the title-block context
Cross-reference labels Project properties → cross-references same as element labels

2. Folio and position variables

These resolve on element labels, conductor texts and cross-reference labels.

Variable Becomes
%f folio index, 1-based
%id the same folio index — %f and %id are identical here
%F the folio field, i.e. whatever the folio's Folio setting renders to
%total total number of folios in the project
%M plant (installation) of the folio
%LM location / machine (locmach) of the folio
%l the row letter of the element's position in the border
%c the column number of the element's position
%prefix the element's prefix

%f and %F are not interchangeable

%f is the folio's index — a plain number. %F inserts the folio field, which is itself a formula. QET's default for that field is %id/%total, so on folio 3 of 12:

%f  →  3
%F  →  3/12

Both then read naturally in a label, which is why the difference goes unnoticed until someone changes the folio field and every element label changes shape with it. If you want the number, use %f.

%c counts from 0 or 1 depending on a preference

The column number comes out one lower when the columns start at 0 preference is set. The same project opened by two people with different settings produces different labels. If labels must be stable across a team, agree that setting first.


3. Wire variables

Only on conductor formulas:

Variable Becomes
%wf conductor function
%wv tension / protocol
%wc wire colour
%ws wire section

4. Sequence variables

Auto-numbering supplies numbered sequences. Each comes in a per-project and a per-folio flavour, and each takes a trailing index — _1 is the first sequence you defined in that numbering scheme, _2 the second, and so on.

Family Per project Per folio
Unit %sequ_1 %sequf_1
Ten %seqt_1 %seqtf_1
Hundred %seqh_1 %seqhf_1
Alphabetic %seqa_1
Wrap %seqw_1

A sequence variable whose index does not exist in the current numbering scheme is left in the text as-is. Seeing a literal %sequ_2 on a folio means the scheme defines only one sequence, not that numbering failed.


5. Element information variables — %{…}

Braced variables pull from the element's own information fields:

%{label} %{manufacturer_reference}

Commonly used: %{label}, %{plant}, %{location}, %{function}, %{comment}, %{description}, %{designation}, %{manufacturer}, %{manufacturer_reference}, %{machine_manufacturer_reference}, %{supplier}, %{quantity}, %{unity}.

Also available: %{auxiliary1}%{auxiliary4} and their description_, designation_, manufacturer_, manufacturer_reference_, supplier_, quantity_ and unity_ variants; the PLC fields %{plc_type}, %{plc_address}, %{plc_function}, %{plc_comment}, %{plc_crossref}, %{plc_t1}%{plc_t4}, %{plc_tc}; the conductor fields %{conductor_color}, %{conductor_section}, %{tension_protocol}; and %{void}, which resolves to nothing.

The list is hard-coded, and four fields are missing from it

%{…} substitution is a fixed list in AssignVariables::replaceVariable(), not a lookup over every information field. QETInformation::elementInfoKeys() lists 61 information keys; 59 braced variables are recognised, and they do not fully overlap.

Two keys are absent by design: formula (it is the formula) and xref. Nine more have no braced variable at all:

%{machine_manufacturer_reference_auxiliary1}
%{machine_manufacturer_reference_auxiliary2}
%{machine_manufacturer_reference_auxiliary3}
%{machine_manufacturer_reference_auxiliary4}
%{category}  %{model}  %{notes}  %{voltage_rating}  %{current_rating}

You can fill any of these in on an element, and the plain %{machine_manufacturer_reference} resolves normally — but none of the nine is in the substitution list, so they stay on the drawing as literal text. Put the value in another field until this is fixed.

The last five arrived with the smart-device metadata fields and were never added to replaceVariable(); the four auxiliary variants have been missing for longer.

Measured against master 3cbb93075. Earlier revisions of this page said 57 keys, three absent by design and four unexplained — that was correct when written, and the drift is why counting from the source matters.


6. Folio field variables

The folio field is the exception on this page: it is resolved by a different function and understands three variables only.

Variable Becomes
%id this folio's index
%total number of folios
%autonum the folio auto-numbering value

The default is %id/%total. %f, %l, %c, %M, %LM and %{…} do nothing here — they are left in the field verbatim and will be printed on every folio exactly as typed. This is the single most common variable disappointment in QET.


7. Title block variables

Title block template cells use their own mechanism: every key in the title block's context is substituted, in both the braced and bare forms — %{author} and %author both work.

The standard keys are the folio's own information fields: title, author, filename, folio, plant, locmach, indexrev, date, display_folio. Project properties and any custom fields you add to the folio are substituted too.

Two details worth knowing:

  • Keys are substituted longest first, deliberately. Without that, a key named plant would eat the beginning of %plantcode and leave code stranded.
  • Only the braced form %{name} can be discovered — the template editor's list of variables in use is built by scanning for %{…}. A bare %name still resolves, but nothing can enumerate it, so prefer the braced form in templates.

8. Substitution is one pass, in a fixed order

Formulas are not evaluated recursively. QET does a sequence of ordinary text replacements, and the order is fixed:

  1. %F, %f, %id, %total, %M, %LM
  2. %c, %l, %prefix (elements) or %wf, %wv, %wc, %ws (conductors)
  3. title-block fields, then project properties, in both %{name} and %name forms
  4. sequences

Two consequences:

  • %F works because it is expanded first. It inserts the folio field, which may itself contain %id and %total — and those are substituted in the same step, just after. Anything the folio field contains that step 1 does not know about will survive to the drawing as literal text.
  • An unknown variable is never an error. It is simply not replaced. A label showing %seqh_3 or %{machine_manufacturer_reference_auxiliary1} is QET telling you that variable is not resolvable here.

9. Quick reference

I want… Use Where it works
the folio number %f element / conductor / xref labels
the folio number in the folio field %id folio field only
folio number and total, e.g. 3/12 %F element / conductor / xref labels
the element's grid position %l%c element labels
an incrementing number %sequ_1 element / conductor labels
an element's part number on the drawing %{manufacturer_reference} dynamic texts, labels
the plant on a title block %{plant} or %plant title block templates

See also: Linking elements · The project database · Project XML