FORUMS: list search recent posts

Reeplace content of a layer

COW Forums : Adobe After Effects Expressions

<< PREVIOUS   •   FAQ   •   VIEW ALL   •   PRINT   •   NEXT >>
yeikel valdes
Reeplace content of a layer
on Oct 28, 2015 at 2:24:25 am

Hello ,

I am new to After Effects scripting and I have been playing with the language. This is the visual setup of the project I have :



Now , as a test , I have the following script :

app.project.activeItem.layers[1].sourceText.setValue('Hello World')

If I run this little script, I am able to change the text of my layer 1 from This is a test to 'Hello World'.

My question is , how can I do this operation when I am not active at the layer?

As far as I know , if we run :

var activeItemid = app.project.activeItem.id;
alert(activeItemid)


I am able to get the id of the current item :



But , If I try :

app.project.item(activeItemid).layers[2].sourceText.setValue('This is just a test')

It does not work.

Can you explain me how does this work?


Thank you.


Return to posts index


Miguel de Mendoza
Re: Reeplace content of a layer
on Oct 28, 2015 at 9:47:00 am
Last Edited By Miguel de Mendoza on Oct 28, 2015 at 9:47:42 am

You can't access to comp by name directly, you must do it by index or by writing a findComp function like this:

function findComp(compName){
var proj = app.project;

for(var i = 1; i <= proj.numItems; i++){
var comp = proj.item(i);
if(!(comp instanceof CompItem) || comp.name != compName){
continue;
}
else {
return comp;
}
}
}

Other problem is that you only have one layer on your comp, so you can`t acces layer[2]. In layers case, you can acces layer by name. You can write this bellow findComp function:

var myComp = findComp("Text 01");
myComp.layer("Layer 1").text.sourceText.setValue( "Your value");


Return to posts index

yeikel valdes
Re: Reeplace content of a layer
on Oct 28, 2015 at 11:08:57 am

This is exactly what I was looking for. proj.item(i); was the key , and that function you provided is pretty useful. Thank you!


Return to posts index

<< PREVIOUS   •   VIEW ALL   •   PRINT   •   NEXT >>
© 2018 CreativeCOW.net All Rights Reserved
[TOP]