Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revisionPrevious revision
Next revision
Previous revision
templator [2018/03/10 02:13] – [Export Image] o2admintemplator [2024/04/03 07:16] (current) – [Javascript] o2admin
Line 7: Line 7:
   * Copy the selected artwork in the current document and place it on the template, and rasterize it.   * Copy the selected artwork in the current document and place it on the template, and rasterize it.
   * Ask the user for custom information, such as job number, clients name, job title   * Ask the user for custom information, such as job number, clients name, job title
 +  * **(NEW) Run Javascript to fetch additional data** 
   * Automatically replace text in the document such as date, name and any other text you want   * Automatically replace text in the document such as date, name and any other text you want
   * Connect to a URL to get information from a website or database, for example, enter in a job number and return the job name and customer details   * Connect to a URL to get information from a website or database, for example, enter in a job number and return the job name and customer details
Line 50: Line 51:
  
  
 +
 +----
 ==== Find and Replace ==== ==== Find and Replace ====
 Once the template is opened or embedded you can find and replace text in the template.  Once the template is opened or embedded you can find and replace text in the template. 
Line 57: Line 60:
   * **Type Column**   * **Type Column**
     * **Text** Replace with text in the //Default Text/Format// column     * **Text** Replace with text in the //Default Text/Format// column
-    * **Date** Replace with the current Date, See below for date formatting options+    * **Date** Replace with the current Date, See bottom of document for date formatting options \\ \\
     * **Document.name** Replace with document name     * **Document.name** Replace with document name
     * **Document.folder** Replace with document folder     * **Document.folder** Replace with document folder
     * **Document.filename** Replace with document filename     * **Document.filename** Replace with document filename
     * **Document.artboardCount** Replace with number of artboards in the document (excluding newly created template artboard)     * **Document.artboardCount** Replace with number of artboards in the document (excluding newly created template artboard)
-    * **Document.colorSpace** Replace with 'RGB' or 'CMYK' +    * **Document.colorSpace** Replace with 'RGB' or 'CMYK'  \\ \\ 
-    * **Artboard.width** //Default Text/Format// column formats the number, "units,decimals" i.e "inch,0" will be in inches with no decimal places "mm,2" will be milimeters with 2 decimal places +    * **Artboard.width** See Size formatting below 
-    * **Artboard.height** //Default Text/Format// column formats the number, "units,decimals" i.e "inch,0" will be in inches with no decimal places "mm,2" will be milimeters with 2 decimal places +    * **Artboard.height**See Size formatting below 
-    * **Artboard.number** the number of the artboard selected prior to creating the template+    * **Artboard.number** the number of the artboard selected prior to creating the template \\ \\ 
 +    * **Selection.width**  See Size formatting below 
 +    * **Selection.height** See Size formatting below 
 +    * **Selection.count** the number of selected items \\ \\
     * **User Text Input** Prompts the user for text     * **User Text Input** Prompts the user for text
       * //Default Text/Format// column contains the default text       * //Default Text/Format// column contains the default text
Line 83: Line 89:
   * **Input Validation Column** See the User Input Validation Rules at the bottom of this page   * **Input Validation Column** See the User Input Validation Rules at the bottom of this page
   * **User Input Label Column** The label to show on the form if empty the find text will be used as a label   * **User Input Label Column** The label to show on the form if empty the find text will be used as a label
 +
 +----
 +
 +== Size formatting  ==
 +You can format the height, width and scale in the //Default Text/Format// column 
 +
 +The formatting is  "units,decimals,scale" 
 +  * **units** Such as 'mm' 'in' 'pt', the full set of units are supported
 +  * **decimals** (Optional, default=2) The number of decimal points to display
 +  * **scale**  (Optional, default=1) The size is multiplied by the scale, so 1 is no change, 0.5 reduces the number by half, 20 makes the number twenty times larger.
 +
 +Examples
 +  * "inch,0,10" will be in inches with no decimal places 
 +  * "mm,2" will be millimetres with 2 decimal places
 +  * "mm,0,10" will be millimetres with no decimal places and ten times larger 
 +
 +
 +----
 +==== Javascript ====
 +
 +You can run Extendscript or Javascript to modify the document and return additional text changes to Templator. Your code will be wrapped in a function, so ensure that you include a return statement with the required data structure.
 +
 +Your code must return the standard object indicating success and any error messages/text changes, see the next section.
 +
 +**Warning: Make sure your code is self-contained and does not pollute the global scope**
 +
 +==ExtendScript in Illustrator==
 +  * Runs the code in Extendscript in Illustrator allowing you to modify and get information from the document. 
 +  * Note that ExtendScript and not modern ES6 Javascript and does not support the latest features of Javascript. see[[ https://ai-scripting.docsforadobe.dev/|Adobe scripting reference for details]].\\
 +
 +== Extendscript Example ==
 +<sxh javascript; >
 +var d = new Date;
 +var success = false;
 +
 +data.textChanges.push({find: "{filename}", type: "activeDocument.name"});
 +data.textChanges.push({find: "*year*", type: "text", value: d.getFullYear()});
 +
 +if(success){
 +    return {
 +        success: true,
 +        data: data
 +    };
 +}
 +
 +return {
 +    success: true,
 +    errorMessage: 'No custom code setup'
 +};
 +</sxh>
 +
 +== Javascript in CEP/NodeJS ==
 +  * Runs the code in the CEP Panel of PowerScripts, this is modern Javascript running on NodeJS, see https://github.com/Adobe-CEP/CEP-Resources.    
 +  * Note that the following libraries are already loaded CSInterface, JQuery, Lodash, Moment.js, Numeral-js. 
 +  * You can run ExtendScript code using CSInterface.evalScript.
 +  * To asynchronously get data, return a Function, This function will be called with the first argument data and the second a callback
 +
 +== Javascript/Node Async Example ==
 +<sxh javascript; >
 +return function getWebsite(data, callback){
 +     $.get("https://www.google.com",function(html){
 +         data.textChanges.push({find: "{html}", type: "text", value: html });
 +         callback({ success: true, data: data });
 +     });
 +}
 +</sxh>
 +
 +----
 ==== External Data ==== ==== External Data ====
-This gives you the option of retrieving data from an external source, such as a custom webpage linked to a database+This gives you the option of retrieving data from an external source, such as a custom webpage linked to a database to Find and Replace text.
-  * **URL** contains the URL address, Note that this can contain find and replace characters, so, for example, you can use http://webserver/database.php?jobid={id} where {id} is a user input. This allows you to ask users for things like a job number, then use that in your URL.+
  
-The server must return data in the following JSON object\\ +  * **URL** contains the URL address, Note that this can contain find and replace characters, so, for example, you can use **http://webserver/database.php?jobid={id}** where {id} is from Javascript or user input. This allows you to ask users for things like a job number, then use that in your URL. 
-''  {''\\ + 
-''    success: ture|false,''\\ +The server must return data in the following JSON object, see below 
-''      errorMessage: string,''\\ + 
-''  data: { ''\\ +---- 
-''cat: "dog"''\\ +==== External URL and Javascript Return Data Format==== 
-''green: "blue"''\\ +The Javascript Extendscript must return the following, and the external webpage must return this in JSON. 
-''  }''\\+ 
 +<sxh javascript; > 
 +
 +    success: true|false, 
 +    errorMessage: string, 
 +    data: { 
 +         textChanges:
 +              {find: "{{animal}}": type: "text", value: "Cat" } 
 +         ] 
 +    } 
 +</sxh>
  
   * **success** is required. Boolean true or false   * **success** is required. Boolean true or false
   * **errorMessage** is optional. When success=false this message will be displayed.    * **errorMessage** is optional. When success=false this message will be displayed. 
-  * **data** is an objectwith property-value pairsThe program will add curly brackets to the property name and replace that with the valueSo in the example above "{cat}" will be replaced with "dog" and "{green}" will be replaced with "blue"+  * **data.textChanges** is an array of objects, {find: "textToFind", type: "text", value: "newText"}Changes are made in reverse order  so you can bypass an existing replacement by pushing one oneto the end of the array. 
 +  * Replacement types:  
 +    * 'text' - Replace find text with value (if type is not included in the object text is assumed) 
 +    * 'date'  - Replace find text with today's date using the format defined in value  
 +    * 'template.name' 
 +    * 'document.folder' 
 +    * 'document.name' 
 +    * 'document.filename' 
 +    * 'document.rulerunits' 
 +    * 'document.colorspace' 
 +    * 'document.artboardcount' 
 +    * 'template.width': - value contains the units to use 
 +    * 'template.height': - value contains the units to use 
 +    * 'artboard.width': - value contains the units to use 
 +    * 'artboard.height' - value contains the units to use 
 +    * 'artboard.number' 
 + 
 + 
  
 +----
 ==== Artwork ==== ==== Artwork ====
 This option allows you to copy the currently selected artwork to the template and resize it. This has been designed for creating approval forms. This option allows you to copy the currently selected artwork to the template and resize it. This has been designed for creating approval forms.
Line 109: Line 211:
   * **Move X/Move Y** Allows you to move the artwork to an exact position on the artboard.   * **Move X/Move Y** Allows you to move the artwork to an exact position on the artboard.
  
 +
 +----
 ==== Folders ==== ==== Folders ====
  
Line 115: Line 219:
   * **Open folder** Tick to open in OSX Finder or Windows Explorer after being created   * **Open folder** Tick to open in OSX Finder or Windows Explorer after being created
  
 +
 +----
 ==== Save ==== ==== Save ====
 Saves the document as an Illustrator file Saves the document as an Illustrator file
Line 128: Line 234:
   * **Prompt for Filename** If unticked then the PowerScript will save without asking to confirm the filename   * **Prompt for Filename** If unticked then the PowerScript will save without asking to confirm the filename
  
 +
 +----
 ==== Export PDF ==== ==== Export PDF ====
 Exports the document as an Illustrator file Exports the document as an Illustrator file
Line 148: Line 256:
  
  
 +
 +----
 ==== Export Image ==== ==== Export Image ====
 Exports the Template Artboard as an Image Exports the Template Artboard as an Image
Line 238: Line 348:
  
 ===== Release Notes ===== ===== Release Notes =====
 +
 +==== Version 2.0.0 ====
 +  * Added preview images and abibility to generate previews
 +  * Added in more data types, selection.width, selection.height,selection.count
 +  * Added in Scale for measurements
 +  * Added in Javascript and Extendscript support
  
 ==== Version 1.3.0 ==== ==== Version 1.3.0 ====