Create Text Selector that Incrementally Selects Each Line of Text
This script will take a text layer with multiple lines, and create a new range selector. It will create keyframes that incrementally select each line of text. We use this a lot for animating lists and things. You can than easily apply properties to the selector.
/*********************************************/
// make sure a comp is selected
var activeItem = app.project.activeItem;
if (activeItem == null || !(activeItem instanceof CompItem))
{
alert("You need to select a layer before running this script");
}
else
{
// make sure at least one layer is selected
var selectedLayers = activeItem.selectedLayers;
if (selectedLayers.length != 1 )
{
alert("Select one layer before running this script.");
}
else
{
app.beginUndoGroup("Create Text Selector");
for(i=0; i<selectedLayers.length; i++)
{
//If Text layer
var theTextLayer = selectedLayers[i];
CreateTextSelector(theTextLayer);
}
app.endUndoGroup();
}
}
function CreateTextSelector(theTextLayer)
{
var lineCount = 1;
var layerText = String(theTextLayer.text.sourceText.value);
for(i=0; i<=layerText.length; i++)
{
if(layerText.charCodeAt(i) == 13)
lineCount++;
}
var theTextProperties = theTextLayer.property("ADBE Text Properties");
var theAnimators = theTextProperties.property("ADBE Text Animators");
// add a Text Animator property to control the highlight style
var highlightAnimator = theAnimators.addProperty("ADBE Text Animator");
var highlightSelectors = highlightAnimator.property("ADBE Text Selectors");
// add a Range Selector property to control the highlight timing
var highlightSelector = highlightSelectors.addProperty("ADBE Text Selector");
// define the range selector's Advanced (7) property group
var advancedSelector = highlightSelector.property("ADBE Text Range Advanced");
// define the Advanced property group's Unit (1) property and set to Index (percentage = 1, index = 2)
var unitsProperty = advancedSelector.property("ADBE Text Range Units");
unitsProperty.setValue(2);
// base sur ligne
var basedOnProperty = advancedSelector.property("ADBE Text Range Type2");
basedOnProperty.setValue(4);
// define the range selector's Start (4) and End (5) properties and set both to zero
var rangeStartProp = highlightSelector.property("ADBE Text Index Start");
var rangeEndProp = highlightSelector.property("ADBE Text Index End");
var animLength = .5;
var animSpacing = 2;
for(j=0; j<lineCount; j++)
{
var inPoint = theTextLayer.inPoint + (animSpacing * j);
var outPoint = theTextLayer.inPoint + animLength+(animSpacing * j);
startKey = rangeStartProp.addKey(inPoint);
rangeStartProp.setValueAtKey(startKey, (j<1)?(0)
j-1));
startKey2 = rangeStartProp.addKey(inPoint+animLength);
rangeStartProp.setValueAtKey(startKey2, j);
endKey = rangeEndProp.addKey(inPoint);
rangeEndProp.setValueAtKey(endKey, j);
endKey2 = rangeEndProp.addKey(inPoint+animLength);
rangeEndProp.setValueAtKey(endKey2, j+1);
}
}
function SetKey(myLayer)
{
opacProp = myLayer.property("Opacity");
inPoint = myLayer.time;
outPoint = inPoint + .5;
var startVal = 100;
if(opacProp.numKeys > 0)
startVal = opacProp.value;
inKey = opacProp.addKey(inPoint);
opacProp.setValueAtKey(inKey, startVal);
outKey = opacProp.addKey(outPoint);
opacProp.setValueAtKey(outKey, 0);
}
Comments