Creative Communities of the World Forums

The peer to peer support community for media production professionals.

Activity Forums Adobe After Effects Expressions Alter text layer name based on content

  • Alter text layer name based on content

    Posted by Chris Meadmore on November 3, 2014 at 8:25 am

    I’m in need a script that automatically changes the text layer names in my project based on the layer content.

    Additionally it would need to add a prefix “^” and remove all spaces and symbols. Also it would only make use of the first 4 words. For example:

    Ben recently voted no in the election

    ^benrecentlyvotedno

    I’ve been trawling the net but can’t find any resources that might help. Any suggestions welcome!

    Thanks.

    Chris Meadmore replied 11 years, 5 months ago 2 Members · 4 Replies
  • 4 Replies
  • Dan Ebberts

    November 3, 2014 at 7:53 pm

    I think that will look something like this:


    var myComp, myLayer, myStr,mySplitStr,myName;
    for (var i = 1; i <= app.project.numItems; i++){
    myComp = app.project.item(i);
    if (myComp instanceof CompItem){
    for (var j = 1; j <= myComp.numLayers; j++){
    myLayer = myComp.layer(i);
    if (myLayer instanceof TextLayer){
    myStr = "^" + myLayer.property("Text").property("Source Text").value.text;
    mySplitStr = myStr.split(" ");
    myName = "";
    for (var k = 0; k < Math.min(mySplitStr.length,4); k++){
    myName += mySplitStr[k];
    }
    myLayer.name = "^" + myName.replace(/\W+/g, "").toLowerCase();
    }
    }
    }
    }

    Dan

  • Chris Meadmore

    November 3, 2014 at 9:09 pm

    Thats brilliant Dan, thanks!

    Only question, how can I get this to affect all text layers project wide? Currently it will only affect the first layer in an active comp.

    Cheers,
    C

  • Dan Ebberts

    November 3, 2014 at 9:28 pm

    Ooops–type. Well that’s what I get for only testing with one comp / one layer. Try this:


    var myComp, myLayer, myStr,mySplitStr,myName;
    for (var i = 1; i <= app.project.numItems; i++){
    myComp = app.project.item(i);
    if (myComp instanceof CompItem){
    for (var j = 1; j <= myComp.numLayers; j++){
    myLayer = myComp.layer(j);
    if (myLayer instanceof TextLayer){
    myStr = "^" + myLayer.property("Text").property("Source Text").value.text;
    mySplitStr = myStr.split(" ");
    myName = "";
    for (var k = 0; k < Math.min(mySplitStr.length,4); k++){
    myName += mySplitStr[k];
    }
    myLayer.name = "^" + myName.replace(/\W+/g, "").toLowerCase();
    }
    }
    }
    }

    Dan

  • Chris Meadmore

    November 8, 2014 at 3:17 pm

    That worked perfectly, thanks for your help Dan!

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