Creative Communities of the World Forums

The peer to peer support community for media production professionals.

Activity Forums Adobe After Effects Expressions Reeplace content of a layer

  • Reeplace content of a layer

    Posted by Peter Parker on October 28, 2015 at 2:24 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.

    Peter Parker replied 10 years, 6 months ago 2 Members · 2 Replies
  • 2 Replies
  • Miguel De mendoza

    October 28, 2015 at 9:47 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");

  • Peter Parker

    October 28, 2015 at 11:08 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!

We use anonymous cookies to give you the best experience we can.
Our Privacy policy | GDPR Policy