Scripting Module
Using the ‘monitorFolder’ method
The Scripting Module now provides a mechanism to automatically execute an ExtendScript file when a specific ‘trigger’ file is dropped into a monitored folder. Starting monitoring The ‘monitorFolder’ method should be called on the EasyCatalog object to begin polling a specific folder – e.g.
1 2 3 4 5 6 | app.easycatalogObject.monitorFolder(File("~/Drop Folder Test/Script/myscript.jsx"),ย File("~/Drop Folder Test/In"), File("~/Drop Folder Test/Processing"), File("~/Drop Folder Test/Processed"), File("~/Drop Folder Test/Errors"), ".*\.xml"); |
Four folders are required for the monitoring process: An ‘in‘ […]
Scripting Support For Links
ecLink Class From 2022, an ecLink class has been added to the scripting module to enhance the scriptability in the creation, inspection and modification of links. This represents an EasyCatalog link, either text or frame based. An ecLinks collection exists on most InDesign layout objects. Basic Properties A link is described using 3 basic properties: […]
Replacing Delimited Field Names With Field Content
The example below replaces field names delimited between { and } with the field content. E.g: “This is a field with another field {name} inside” The replaces “name” with the contents of field called “name”.
1 2 3 4 5 6 7 8 9 | -- Searches a field called "name" for fields delimited -- between { and } and replaces them with field content str = field(name) while str:match("{(.-)}") do word=str:match("{(.-)}") str = string.gsub(str, "{" .. word .. "}", field(word)); end return str |
Custom Menus and Dialogs
Overview Lua scripts can be integrated with EasyCatalog to provide custom menus and dialog boxes. User Interface is provided by the the InDesign Scripting DOM, which offers dialog creation and control. Details on how to access this from Lua are here. Creating a Custom Menu Option Adding a custom menu option is a case of […]
Accessing the InDesign Scripting DOM via Lua
Overview The InDesign Scripting DOM provides full access to the creation and manipulation of all content within InDesign. By combining this the speed of Lua with the data access and control facilities of EasyCatalog, it’s possible to create data driven content in virtually any format. Accessing The InDesign Scripting DOM can be accessed via Lua […]
Creating a Calendar using LUA
This example code creates a calendar tabular field using data where each record is an event on a calendar. The data has fields contain the month and year. ย GROUPSCRIPT is used to call the script for each month group. This data can then be paginated using Master based pagination.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 | -- GROUPSCRIPT gets passed a 'recordset' object. -- the 'Month', 'Year' and 'Day' are fields in the data -- Each cell is filled with 'Title' and 'Time' imonth = tonumber(recordset:getrecord(1):field('Month'):content()); iyear = tonumber(recordset:getrecord(1):field('Year'):content()); function get_day_of_week(dd, mm, yy) dw=os.date('*t',os.time{year=yy,month=mm,day=dd})['wday'] return dw,({"Sun","Mon","Tue","Wed","Thu","Fri","Sat" })[dw] end function get_days_in_month(month, year) local days_in_month = { 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 } local d = days_in_month[month] -- check for leap year if (month == 2) then if year % 4 == 0 then if year % 100 == 0 then if year % 400 == 0 then d = 29 end else d = 29 end end end return d end function populate_cell(row, col, day_of_week) for record=1, recordset:size() do myrecord = recordset:getrecord(record); data_day = tonumber(myrecord:getfield('Day'):content()); if data_day == day_of_week then this_entry = "<p>" .. myrecord:getfield('Title'):content() .. "</p>" .. "<p>" .. myrecord:getfield('Time'):content() .. "</p><br/>" table:cell(row,col):setcontent(table:cell(row,col):getcontent() .. this_entry); end end end table = TABLE.new(); table:cell(1,1):setcontent("Sunday"); table:cell(1,2):setcontent("Monday"); table:cell(1,3):setcontent("Tuesday"); table:cell(1,4):setcontent("Wednesday"); table:cell(1,5):setcontent("Thursday"); table:cell(1,6):setcontent("Friday"); table:cell(1,7):setcontent("Saturday"); days_in_month = get_days_in_month(imonth, iyear); first_day_in_month = get_day_of_week(1,imonth,iyear); for day=1,days_in_month do offset = (day-1) + first_day_in_month; row = math.floor((offset-1) / 7) column = math.floor(offset-1) % 7; table:cell((row*2)+2,column+1):setcontent(day); populate_cell((row*2)+3,column+1, day); end; table:present(); |
Custom Image Import
For images that are sourced externally but are not URL or File based, the “Custom” option can be chosen in the picture location section of the field options. When this is set, EasyCatalog looks for a file called ‘CustomImageImport.jsx’ in the ‘Scripts’ folder of a data source. Here’s a simple example that displays the field […]
Custom Relinking of Fields
The standard “Adopt Fields” method of relinking assumes field names and key field values are consistent between the existing links and the new data. ย It was designed to link fields from one data source to another, and as such is limited to changing the key element of a link. In some circumstances it may be […]
Using LUA commands to create an index/glossary
Consider a data source with the following data. This example creates a glossary of all the words in the ‘Glossary’ field, showing the pages theyย appear on. The words are sorted alphabetically and the pages are numerical within each word. The resulting output looks something like: big – p 13,14, bill – p 13, black […]
Accessing Guide Based Pagination Progress on InDesign Server
There is a script called โPaginationProgress.jsxโ which you can place in the Data Sources โScriptsโ folder. This is passed script arguments: โdatasource” ย : The Data Source Name โstepindexโ ย : Current Step Index โstepcountโ : ย Total Number of Steps โstep messageโ : Related Message You can accessย them like this: var stepCount = Number(app.scriptArgs.getValue(“stepcount”));
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:
1 | [[if (field('new') == '1') then;]]NEW![[end;]] |
In this example, if the contents of the ‘new’ field are equal to ‘1’ the text NEW! will be output. […]
Get the name of the selected data source
While you can get the selected panel (DSV) object. To get the name of the data source, the parent object needs to accessed:
1 2 3 4 | var ec = app.easycatalogObject; var myDSV = ec.selectedDataView(); var myDS = myDSV.parent; alert(myDS.dataSourceName); |
Setting pagination options via a script
The options shown on the “Paginate” dialog can all be set using the ‘setPaginationOption‘ scripting method which is available on the datasource object.ย This method takes two parameters: the name of the option to set and the value to set it to.
1 | myDS.setPaginationOption("templatedocumentpath","Macintosh HD:mytemplate.indd"); |
The value used for the ‘name‘ parameter can be determined by examining […]
Referencing a field in a CALLSCRIPT script
Here’s an example CALLSCRIPT script that references record data passed to it:
1 2 3 4 5 6 7 8 9 10 11 | var myFieldContents = myRecord["Store List ID"]; var mySplitContents = myFieldContents.split(","); var myNbrOfChunks = mySplitContents.length; var myCodeList = "" for (thisChunk = 0;thisChunk < myNbrOfChunks;thisChunk++) { var myChunk = mySplitContents[thisChunk]; var myCode = String(myChunk.substring(myChunk.length - 2, myChunk.length)) var myCodeList = myCodeList + " " + myCode } myCodeList; |
Using a post image import script to manipulate an image
After EasyCatalog imports an image, it looks for a script called “PostImageImport.jsx” in both the Data Source->Scripts folder and the EasyCatalog Workspace Folder->Scripts folder. This can be used to manipulate an image after import. The example below applies the DETECT EDGES clipping path setting:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 | // Sample script to change the clipping path to detect edges // These can be used to extract the field name and content of the image field: //alert(app.scriptArgs.getValue("field")); //alert(app.scriptArgs.getValue("fieldContent")); // Get the internal ID of the container, passed in from EasyCatalog var myID = Number(app.scriptArgs.getValue("id")); // Get the frame var myFrame = app.activeDocument.pageItems.itemByID(myID) // Get the image var myImage = myFrame.allGraphics[0]; // Set the clipping path myImage.clippingPath.clippingType = ClippingPathType.DETECT_EDGES; // Re-fit the image myFrame.fit(FitOptions.proportionally); |
A quick way to retrieve a list of data sources
A quick way to retrieve a list of data sources…
Iterate down a book, checking documents for changes and updating the panel
Choose a book, choose a datasource, iterate through the book checking documents for changes and updating the panel with the changes…
Iterate down one data source, filtering another panel based on the contents of a field
Iterate down one data source, filtering another panel based on the contents of one of the fields…
Iterate through a data source, exporting one document per record
Iterate through a data source, exporting one document per record in the panel…
Open data source and output contents of a named field
Open a data source, create a view for it and then output to the JavaScript console the contents of a named field…
Open data source, sync with data source, open document and paginate at guide positions
Open a data source, close all the panels for it, synchronize with new data, open a new panel, open a document, paginate at guide positions…
Open document, update furniture and save under new name
Open a document, open a data source, update furniture, close data source, save document to a new name…
Search and Replace multiple fields
This script shows a dialog that allows for up to 10 search and replace fields to be done at one time…