# PersoFiles scripting

Make repeatable changes to a loaded PersoFile using short, readable commands. Open Edit, then Scripts on the right. Start with list fields and list layers to discover the field keys and artwork IDs in your design.

## Your first script

```text
holderName=Frank;
select field:holderName;
move 2 0;
set fill "#234f70";
```

Replace holderName with a field key from your own file. The assignment changes its raw default/sample value across every placement, including linked QR and barcode objects. It does not change data belonging to an existing customer order.

## Run, review, save

Click Run script, or press Ctrl/Cmd+Enter in the script box. A successful run is one Undo step. Review the canvas, then Save when you want to keep the result. A script never saves or publishes a release automatically. If any statement or final validation fails, none of the script's design edits are applied.

## Statements and quoting

Separate commands with semicolons or new lines. Names and field keys are case-sensitive. Quote arguments containing spaces or semicolons with single or double quotes. Inside quotes, use \n for a new line, \t for a tab and \\ for a backslash. Escape a quote with a backslash. Lines beginning with // are comments. A semicolon inside quotes belongs to the value.

```text
// One value containing a semicolon
holderName="Frank; Jones";
field.set holderName format "Member: *";
```

A bare assignment uses all text after = as the value; unquoted leading/trailing whitespace is trimmed. Quote a value when those spaces matter. The scripting engine has no JavaScript evaluation, loops, functions, arbitrary network access or filesystem access. Limits: 2 MB of script text, 1000 statements and 10000 selected-object operations per run.

## Selecting objects

Use select followed by one or more selectors. field:key includes all text/image placements and linked codes using that field, on both sides. id:svgId chooses a stable SVG element ID. layer:0/1 chooses a current layer path; paths can change after additions/reordering, so IDs are preferable. label:Exact label chooses matching artwork labels. tag:rect chooses that element type on the current default side. side:rear chooses top-level items on that surface. all selects top-level items on the default side; none clears the selection.

```text
list layers;
select id:your-panel-id;
set fill "#e8f1f6";
select "label:Company logo";
move 1 0;
```

Selection is the script's working selection. It is reported in the output and retained between successful runs while the Scripts panel remains mounted. It does not depend on which field happened to be clicked on the canvas. Adding/duplicating an item selects the new item(s). Selecting a group and its child operates on the group once.

## Units and geometry

Move, position, size, surface dimensions, textbox dimensions and fit widths use millimetres. Position means the top-left of the measured bounding box within the object's own surface. Transforming a parent group is accounted for. Scale uses factors; rotate uses clockwise degrees. Font sizes, padding, stroke-width and raw data-* dimensions use local SVG units. Use size for physical QR/barcode dimensions; QR codes stay square.

Alignment and gap spacing operate within one side at a time. Select at least two objects for alignment/increase/decrease, and at least three for equal gaps. They use the combined selection's outer bounds. Text and artwork sizes are measured in the browser with the same editor preview. Rotated textboxes/codes keep their local axes when resizing.

## Values, formats and field options

Field assignments and text commands store raw sample values. A field format such as 101-* is applied by the shared renderer; do not include the prefix in the raw value as well. Visible controls the personalisation form, not visibility on the card. Start blank clears the initial value when personalisation starts; it does not erase the design's sample text. Required is checked for visible fields at finalisation.

```text
field.set holderName required true;
field.set holderName visible true;
field.set holderName startBlank false;
field.set holderName format "Member: *";
```

## CFQL background

This engine keeps the familiar field=value and semicolon approach from CFQL Manager. It is a new PersoFiles command language, not a compatibility interpreter for every old CFQL keyword. Only the commands documented here are supported. Unknown commands produce an error with the source line. Undo/redo, saving, publishing releases, library deletion, zoom and editor-only diagnostic views remain explicit controls in the app.


# Command reference

## select

Replace the working selection. Selectors: field:key, id:svgId, layer:0/1, label:Exact label, tag:rect, side:front, all, none. Selectors combine as a union; quote selectors containing spaces. Selection is internal to the script.

```text
select selector [selector …]
```

```text
select field:holderName; move 2 0
```

```text
select "label:Background panel"; set fill "#163b56"
```

## side

Set the default side for subsequent additions. Does not change existing objects.

```text
side surfaceId
```

```text
side rear
```

## list

Print IDs, paths and field keys to the Scripts output. Use these exact selectors in later commands.

```text
list [layers|fields|surfaces|selection]
```

```text
list layers
```

## field.set

Set label, key, type, required, visible, startBlank, defaultValue or format. Booleans must be true/false. Renaming updates bindings; changing a bound field type is rejected.

```text
field.set key property value
```

```text
field.set holderName visible true
```

```text
field.set holderName format "Member: *"
```

## field.add

Create a field and its first placement. A textbox is a multiline text field. Selects the new placement.

```text
field.add key label [text|image|textbox] [surfaceId]
```

```text
field.add memberNumber "Member number" text front
```

## field.place

Place an existing field again; its value and options are shared. Selects the new placement.

```text
field.place key [surfaceId]
```

```text
field.place holderName rear
```

## field.delete

Remove a field definition and all text/image/code placements that use it.

```text
field.delete key
```

```text
field.delete unusedField
```

## bind

Bind selected plain static text/images to an existing compatible field, or create a field for each selected object when omitted. For codes, use source instead.

```text
bind [existingFieldKey]
```

```text
select id:caption; bind holderName
```

## source

Use an existing text field as the dynamic source of selected QR/barcodes.

```text
source fieldKey
```

```text
select id:memberBarcode; source memberNumber
```

## source.new

Create a new text source for each selected QR/barcode using its sample content.

```text
source.new
```

```text
select id:memberBarcode; source.new
```

## move

Move selected objects by millimetres in their own surface coordinates; accounts for parent transforms.

```text
move dxMm dyMm
```

```text
select field:holderName; move 2 -1
```

## position

Set each selected object’s surface bounding-box top-left in millimetres.

```text
position xMm yMm
```

```text
position 10 12
```

## size

Resize selected objects to surface bounding dimensions in mm. QR dimensions must match; text uses its current measured bounds. For rotated textboxes/codes, local axes follow the object.

```text
size widthMm heightMm
```

```text
size 40 12
```

## scale

Multiply dimensions by positive factors. QR codes stay square.

```text
scale horizontalFactor verticalFactor
```

```text
scale 1.1 1.1
```

## rotate

Rotate clockwise around each selected bounding-box centre. Spans require selecting their parent text.

```text
rotate degrees
```

```text
rotate 90
```

## align

Align at least two selected objects within one surface. Reference is the outer selection bounds.

```text
align left|right|top|bottom|hcenter|vmiddle
```

```text
select id:a id:b; align left
```

## spacing

Equalise gaps (at least three items), or increase/decrease gaps (at least two). Default step is 1 mm; decrease stops at touching. Select within one surface.

```text
spacing equal|increase|decrease horizontal|vertical [stepMm]
```

```text
select id:a id:b id:c; spacing equal vertical
```

## set

Change colours, outlines, opacity, typography or code properties on selected objects. See the property reference. Uses existing editor validation.

```text
set property value
```

```text
set fill "#234f70"
```

```text
set font-size 28
```

```text
set data-box-line-height 1.4
```

## text

Change static wording, or raw default/sample values of selected bound text/code source fields. Shared fields update once across all placements.

```text
text value
```

```text
select field:holderName; text "Frank Jones"
```

## image

Set selected static images to an embedded PNG/JPEG/WebP data URL. No URL fetching or local-file access.

```text
image dataUrl
```

```text
select id:logo; image "data:image/png;base64,..."
```

## image.fit

Fit selected image contents inside their frames (meet) or crop to fill (slice).

```text
image.fit meet|slice
```

```text
image.fit slice
```

## textbox

Enable/resize a multiline text area, or disable multiline layout. Select plain text. Typography uses bundled fonts.

```text
textbox on widthMm heightMm | textbox off
```

```text
textbox on 45 15
```

```text
set data-box-align justify
```

## fit

Enable single-line shrink fitting for selected bound plain text using Noto Sans; font sizes are SVG units. Width is mm.

```text
fit widthMm minimumFontSize [preferredFontSize] | fit off
```

```text
select field:holderName; fit 45 10 28
```

## add

Add and select an object. New codes create required dynamic content fields.

```text
add panel|circle|text|textbox|icon|image|qrcode|barcode [surfaceId]
```

```text
add panel front; size 30 10; set fill "#e8f1f6"
```

```text
add barcode; source memberNumber
```

## delete

Remove selected placements/artwork, keeping their field definitions. Use field.delete to remove a definition and all its placements.

```text
delete
```

```text
select id:oldDecoration; delete
```

## duplicate

Duplicate selected static artwork or codes; codes share their source. Dynamic text/image placements use field.place instead.

```text
duplicate
```

```text
select id:accent; duplicate; move 5 0
```

## front

Bring selected objects to the front within their current parent.

```text
front
```

```text
front
```

## back

Send selected objects to the back within their current parent.

```text
back
```

```text
back
```

## order

Reorder one selected item next to one sibling. Selectors must identify exactly one compatible peer.

```text
order before|after selector
```

```text
select id:accent; order before id:caption
```

## lock

Keep selected group components together as a single artwork layer.

```text
lock
```

```text
select id:logoGroup; lock
```

## unlock

Expose selected group components for editing. Code components cannot be unlocked.

```text
unlock
```

```text
select id:logoGroup; unlock
```

## icon

Replace selected static artwork with a built-in icon or a standalone vector SVG. Built-ins: cross, heart, star, shield, person, phone, check, warning.

```text
icon builtinName | icon svgMarkup
```

```text
icon heart
```

## asset.add

Add an asset from your asset library. The editor loads it by ID; no arbitrary network access.

```text
asset.add assetId [surfaceId]
```

```text
asset.add "your-asset-id" front
```

## asset.replace

Replace selected static artwork with an asset, preserving its area.

```text
asset.replace assetId
```

```text
asset.replace "your-asset-id"
```

## surface.add

Add an empty named surface. Select it as the default for subsequent additions.

```text
surface.add id label widthMm heightMm
```

```text
surface.add rear Rear 85.6 54
```

## surface.set

Change surface label, physical dimensions or ID using the surface editor.

```text
surface.set id label|widthMm|heightMm|id value
```

```text
surface.set front label Front
```

## surface.remove

Remove a surface and its placements. At least one surface must remain; front is protected, as in the editor.

```text
surface.remove id
```

```text
surface.remove rear
```

## design.set

Update file metadata. Tags are a quoted JSON array. Folder segments use |.

```text
design.set name|path|description|tags value
```

```text
design.set name "Staff membership"
```

```text
design.set tags '["staff","membership"]'
```

## design.svg

Replace the complete SVG source. Existing field definitions remain. Final validation rejects unsafe SVG or missing field references.

```text
design.svg svgMarkup
```

```text
design.svg '<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 600 400"><rect width="600" height="400" fill="white"/></svg>'
```

## inherit.detach

Detach the draft from its master, retaining current resolved artwork and fields.

```text
inherit.detach
```

```text
inherit.detach
```

## inherit.reset

Reset fields/artwork to the pinned master while retaining this file’s identity and name. Requires a saved master and server access.

```text
inherit.reset
```

```text
inherit.reset
```

## inherit.rebase

Preview/rebase the draft against another immutable revision of the same master. Keeps overrides; conflicts fail the entire script.

```text
inherit.rebase revisionInteger
```

```text
inherit.rebase 23
```

# Property reference

move, position, size, surface dimensions, textbox dimensions and fit widths use mm. font-size, padding, stroke-width, spacing typography and code data-* size attributes use local SVG units. Prefer size for physical code dimensions.

font-weight: 400/700; font-style: normal/italic; text-anchor: start/middle/end. Multiline align: left/center/right/justify/fill. kerning: on/off. overflow: error/shrink. line distribution: spacing/fill. Use Noto Sans, Noto Serif or Lato for outlined layout. Font-size/min-size support two decimals.

Use source / text / field.set to edit dynamic content. data-qr-border: none/black; data-qr-rounded: true/false. QR remains square. Code128 supports printable ASCII; formatted content must fit its encoding limits.

Scripts edit only the loaded draft. They do not save, publish releases, delete assets or execute JavaScript. A successful run is one Undo step. Failed runs apply no design edits. Reference syntax is inspired by CFQL assignment/separators, not a promise to execute every legacy CFQL command.

fill, stroke, stroke-width, opacity, font-size, font-family, font-weight, font-style, text-anchor, rx, ry, d, points, data-box-align, data-box-line-height, data-box-paragraph-spacing, data-box-letter-spacing, data-box-kerning, data-box-overflow, data-box-min-size, data-box-line-distribution, data-box-height-mode, data-box-padding-top, data-box-padding-right, data-box-padding-bottom, data-box-padding-left, data-qr-size, data-qr-border, data-qr-rounded, data-barcode-width, data-barcode-height
