Using Job Details in ExtendScripts

Use the Templater ExtendScript API to use job details within ExtendScript code. When creating a script using the Templater ExtendScript API, use the $D object to access and manipulate Templater’s internal memory. One of the best ways to understand how to access variables within your registered ExtendScripts is by way of example. The following two examples show how you can use Templater job details within ExtendScripts registered to listen for Templater events.

ClosedAdjust the target composition's work area for each job

For example, assume you want to change the target composition's work area for each job that Templater will process in a batch. You would make use of the $D.target() method to access the target composition and manipulate the start and work area. Follow the steps below to accomplish this:

  1. Add two columns or properties to your data source named workarea-start and workarea-end.
  2. In your data source, for each job's workarea-start value, enter the frame number where you want the work area in the target composition to begin. Then, for each job's workarea-end value, enter the frame number where you want the work area in the target composition to end.
  3. Create a new ExtendScript file and save it as adjust-target-workarea.jsx.
  4. Enter the following code into the adjust-target-workarea.jsx file and save it
    var targetComp = $D.target(),
        comp_fps   = targetComp.frameRate,
        f_start    = parseInt($D.job.get("workarea-start")),
        f_end      = parseInt($D.job.get("workarea-end"));
    
    targetComp.workAreaStart    = (f_start / comp_fps);
    targetComp.workAreaDuration = (f_end / comp_fps) - targetComp.workAreaStart;
  5. Register the adjust-target-workarea.jsx file with the After Update event.
  6. Run a batch render job with Templater with rows or objects that have different workarea-start and workarea-end values. The output corresponding to each row or object has a different work area.

ClosedTruncate text strings and append an ellipsis

As another example, you might want to truncate a text string and append it with an ellipsis before it is injected into a dynamic layer. To do this, follow these steps:

  1. Add a column or property to your data source named headline. Map the headline values to a text layer within an After Effects composition using the Templater Settings effect.
  2. In your data source, for each job's headline value, enter a text string that contains more than ten characters. You can enter strings less than ten characters long, but these will not be truncated as per the following ExtendScript code.
  3. Create a new ExtendScript file and save it as truncate-long-string.jsx.
  4. Enter the following code into the truncate-long-string.jsx file and save it:
    function truncate(word){
    
      var truncated_word;
      var max_characters = 10;
    
      truncated_word = (word.length > max_characters) ? word.slice(0, max_characters) + '...' : word;
    
      return truncated_word;
    
    }
    
    $D.job.set("headline", truncate($D.job.get("headline")));

  5. Register the truncate-long-string.jsx file with the Before Update event.
  6. Using Templater, iterate through a set of rows or objects that have different headline values — some shorter than ten characters, and some longer. Notice that long text strings within the headline layer are post-fixed with three period characters....