<= Previous article ExtendScript + Expression
And so, we have a layout for titles ready. We are moving towards the home stretch. We just have to add the script, supplementing it with methods of copying models to the scene.
We go into the createTitres method and immediately after adding the scene, we start the cycle, traversing the array with the titles data.
function createTitres(data) {
var scenesData = getScenesData();
for(var i = 0; i < scenesData.length; i++) {
var scene = getScene(scenesData[i]);
for (var j = 0; j < data.length; j++) {
var titreName = 'titre-' + j + '-' + scenesData[i].type;
var layer = scene.layers.byName(titreName);
}
}
}
In the loop, we first try to find the title on the stage. To do this, we refer to the layers property of the composition and its byName method . Why we are doing this, we will discuss a little later. For now, let's look at the situation where the method returns null to us , which means there is no layer with that name.
if (!layer) {
var modelName = 'ModelTitre_' + data[j].type + '_' + scenesData[i].type;
var item = getTitreComp(modelName);
}
//………………………………………………………………………………………//
function getTitreComp(modelName) {
var item = getItem(modelName, CompItem);
if (!item) {
alert(' ' + modelName);
return null;
}
return item.duplicate();
}
In the getTitreComp method , we find the title model and, if we haven't found one, return null . If the model is found, we return its duplicate. Next, we rename the duplicate and add it to the scene using the layers.add method , which returns us the layer with the duplicate.
if (item) {
item.name = titreName;
layer = scene.layers.add(item);
}
. editLayer, , ( ) ModelScene, .
, startTime ,
var scene = getScene(scenesData[i]);
var startTime = 0;
editLayer
, getScenesData , layers, .
data.push({
type: item.name.split('_')[1],
width: item.width,
height: item.height,
frameRate: item.frameRate,
duration: item.duration,
layers: item.layers
});
createTitres . editLayer
if (item) {
item.name = titreName;
layer = scene.layers.add(item);
var modelLayer = scenesData[i].layers.byName(modelName);
startTime = editLayer(layer, startTime, modelLayer);
}
editLayer
function editLayer(layer, startTime, modelLayer) {
if (modelLayer) {
// -
} else {
//
}
}
, - , . , .
layer.startTime = startTime;
layer.outPoint = startTime + 5;
, .
,
layer.label = modelLayer.label;
layer.startTime = startTime;
var layerDuration = modelLayer.outPoint - modelLayer.startTime;
layer.outPoint = startTime + layerDuration;
, . , . , , . startTime, layer.outPoint, .
function editLayer(layer, startTime, modelLayer) {
layer.startTime = startTime;
if (modelLayer) {
layer.label = modelLayer.label;
var layerDuration = modelLayer.outPoint - modelLayer.startTime;
layer.outPoint = startTime + layerDuration;
} else {
layer.outPoint = startTime + 5;
}
return layer.outPoint;
}
createTitres. Expressions . , ModelScene_1x1. scene-1x1
startTime = editLayer(layer, startTime, modelLayer);
changeExpression(
item,
'ModelScene_' + scenesData[i].type,
'scene-' + scenesData[i].type
);
//................................................................
function changeExpression(comp, search, replacement) {
for (var i = 1; i <= comp.numLayers; i++) {
var layer = comp.layer(i);
var propGroup = layer.property('ADBE Transform Group');
for (var j = 1; j <= propGroup.numProperties; j++) {
var prop = propGroup.property(j);
if (prop.expression) {
prop.expression = prop.expression.replace(
new RegExp(search, 'g'),
replacement
)
}
}
}
}
changeExpression , . . numLayers. . ADBE Transform Group ( After Effects ). , numProperties. , ModelScene_1x1 titre-1x1.
. , , .
changeExpression(
item,
'ModelScene_' + scenesData[i].type,
'scene-' + scenesData[i].type
);
setText(item.layers.byName('reference_text'), data[j].text)
//................................................................
function setText(layer, text) {
if (layer) {
var property = layer.text.property("Source Text");
var value = property.value;
value.text = text;
property.setValue(value);
}
}
setText reference_text, , .
setText SourceText, text, , , .
. , .
for (var j = 0; j < data.length; j++) {
var titreName = 'titre-' + j + '-' + scenesData[i].type;
var layer = scene.layers.byName(titreName);
if (!layer) {
var modelName = //....
//....
} else {
setText(
layer.source.layers.byName('reference_text'),
data[j].text
);
}
}
. source, , .
. .
#simple simple #simple simple #double double
.
, .
.
, refernce_text.
, , , . , . , . . , .
Documentation on working with layers in ExtendScript here .
Thanks for attention. If these lessons prove useful to someone, it will be nice to learn about projects in which readers apply these skills.
<= Previous article ExtendScript + Expression