Advanced Conditional Processing Using Lua

EasyCatalog supports an embedded version of the Lua programming language.  When text is processed, any commands between  delimiters [[ and ]] are processed using Lua. EasyCatalog supplements Lua with functions to make data access easier. For example:

In this example, if the contents of the ‘new’ field are equal to ‘1’ the text NEW! will be output.  Any InDesign text based content can be entered between the delimiters, such as anchored objects.

Working With The Selection

EasyCatalog uses the SELECTION class to inspect, set and navigate the selection. A call to SELECTION.root() retrieves the root SELECTION object.  This represents what’s dragged to a frame or paginated. This has several methods, size() returns the number of records in the selection and get() retrieves the item for use . Here’s an example that calls a function that outputs NEW! for each record in the SELECTION based on a flag:

Lua is pseudo object oriented.  SELECTION.root() returns a SELECTION object. To call methods on an instance of this object a colon should be supplied, e.g: SELECTION:size().

In the case of relational or grouped panels, the selection can be hierarchical. Here’s an example that traces the hierarchy using simple recursion:

To get the contents of a named field from the SELECTION object , the getcontent() method can be used:

Relational Groups

For relational data sources, the SELECTION object can be used to retrieve a specific relational group using the getgroup() method:

Inserting Content

The TEXT class as a couple of members to insert content into the document.

insert() – Inserts the given text into the text flow. Meta characters, such as ^p, ^t are interpreted:

insertrule() – Inserts a named Formatting Rule:

Retrieving The Insertion Position

The text objects x(), y() and pageindex() methods return information about the current insertion. This allows page positioning based logic:

Lua is also used to control the custom appearance of a fields in the data panel via the field options. Additional command are provided that are not relevant to text processing.