Skip to main content

Text Exploder Scripting API

All functions of TextExploder V2 can also be remote-executed from other scripts. It supports exactly the same functions as the build-in KBar-API, so please refer to the KBar API documentation for the documentation of all available functions.

Using the API is best explained with an example:

/*
This document explains how to remote-execute functions of TextExploder
from other Ae scripts.

The API object used here has the same functions as the KBar API
(see https://mamoworld.com/article/textexploder-kbar-api)
*/

// let's get the API to do something with TextExploder.
// Pass a file object to TextExploder.jsxbin as argument
// of the getTextExploderV2() call
// if it is not in the same folder as this script.
// See definition of this function at the end of this file
var API = getTextExploderV2();

var comp = app.project.activeItem;

// spits the selected layers of the active comp into characters
// all other options are used as stored in the prefs (i.e. as
// they have been used the last time TextExploder was executed from its normal
// UI)
API.explode({split:"characters"});

// splits the first two layers of the active composition into words
// deleting the original layers and
// sorting the generated layers in top to bottom order
API.explode({layerArray:[comp.layer(1),comp.layer(2)], split:"words", deleteOriginal:true, layerOrder:"topToBottom"});




/*
This function creates the textExploderV2 object if it does not exist yet

If scriptFile is undefined, this function assumes that TextExploder.jsxbin is
in the same folder as this script file. Otherwise, please pass a file object
for TextExploder.jsxbin as scriptfile argument.
*/

function getTextExploderV2(scriptFile){
if(typeof textExploderV2 == 'undefined'){
return executeTextExploder(scriptFile);
}
return textExploderV2;


function executeTextExploder(scriptFile){
if(scriptFile === undefined){
scriptFile = getTextExploderScriptFileFromDefaultLocation();
}
if(!scriptFile.exists) throw new Error("could not find file "+scriptFile.fsName);
scriptFile.open("r");
var fileContents = scriptFile.read();
scriptFile.close();

// yes, this is a global variable.
// we use this kbar API to tell TextExploder that it should not show its user interface
// and return its API instead
kbar = { button:{argument:"getAPI"}};
// execute the file --> this should create the textExploderV2 object
var result = eval(fileContents);

// when TextExploder understands the button command, it will set it to undefined.
if(kbar.button !== undefined){
throw new Error("TextExploder didn't understand the getAPI action, is scriptFile pointing to another script?");
}
return result;
}

function getTextExploderScriptFileFromDefaultLocation(){
// get the folder where this script file is located
var myFolder = (new File($.fileName)).parent;
// find TextExploder.jsxbin in the same folder
var scriptFile = new File(myFolder.fsName+"/TextExploder.jsxbin");
return scriptFile;
}
}

What about licenses?

Of course, the API will only work if a proper TextExploder license is installed. If you run in trial mode, the usual trial limitations apply (only the first few layers are generated).