Copy link to clipboard
Copied
How can replace a new text to sourceText of Layer?
I had try this code, but it not allow:
var firstComp = app.project.item(4);
for(var iLayer=1;iLayer<=firstComp.numLayers;iLayer ++)
{
var firstLayer = firstComp.layer(iLayer);
if( firstLayer.sourceText!=undefined && firstLayer.sourceText.numKeys >0 )
{
//firstLayer.sourceText.value="abc";
firstLayer.sourceText.setValue( "abc");
}
}
If you want to replace the text at a particular key, you'd need to use keyValue() to retrieve the current value, and setValueAtKey() to replace the value at that key. So if you wanted, for example, to replace the text at the first keyframe, it might look like this:
var comp = app.project.activeItem;
var layer;
var sourceText;
var textDoc;
for (var i = 1; i <= comp.numLayers; i++){
layer = comp.layer(i);
if (layer instanceof TextLayer){
sourceText = layer.property("Text").property("Source T
...
Copy link to clipboard
Copied
Try this:
var comp = app.project.activeItem;
var layer;
var sourceText;
var textDoc;
for (var i = 1; i <= comp.numLayers; i++){
layer = comp.layer(i);
if (layer instanceof TextLayer){
sourceText = layer.property("Text").property("Source Text");
textDoc = sourceText.value;
textDoc.text = "abc";
sourceText.setValue(textDoc);
}
}
Copy link to clipboard
Copied
It only allow set value when sourceText.numKeys =0,
If sourceText.numKeys >0 , can't replace new text.
Copy link to clipboard
Copied
If you want to replace the text at a particular key, you'd need to use keyValue() to retrieve the current value, and setValueAtKey() to replace the value at that key. So if you wanted, for example, to replace the text at the first keyframe, it might look like this:
var comp = app.project.activeItem;
var layer;
var sourceText;
var textDoc;
for (var i = 1; i <= comp.numLayers; i++){
layer = comp.layer(i);
if (layer instanceof TextLayer){
sourceText = layer.property("Text").property("Source Text");
textDoc = sourceText.keyValue(1);
textDoc.text = "abc";
sourceText.setValueAtKey(1,textDoc);
}
}