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.
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:
- Add two columns or properties to your data source named
workarea-start
and workarea-end
.
- 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.
- Create a new ExtendScript file and save it as adjust-target-workarea.jsx.
- 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;
- Register the adjust-target-workarea.jsx file with the After Update event.
- 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.
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:
- 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.
- 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.
- Create a new ExtendScript file and save it as truncate-long-string.jsx.
- 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")));
- Register the truncate-long-string.jsx file with the Before Update event.
- 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...
.