FORUMS: list search recent posts

Alter text layer name based on content

COW Forums : Adobe After Effects Expressions

<< PREVIOUS   •   FAQ   •   VIEW ALL   •   PRINT   •   NEXT >>
Chris Meadmore
Alter text layer name based on content
on Nov 3, 2014 at 8:25:02 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.


Return to posts index

Dan Ebberts
Re: Alter text layer name based on content
on Nov 3, 2014 at 7:53:44 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



Return to posts index

Chris Meadmore
Re: Alter text layer name based on content
on Nov 3, 2014 at 9:09:51 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


Return to posts index


Dan Ebberts
Re: Alter text layer name based on content
on Nov 3, 2014 at 9:28:58 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



Return to posts index

Chris Meadmore
Re: Alter text layer name based on content
on Nov 8, 2014 at 3:17:06 pm

That worked perfectly, thanks for your help Dan!


Return to posts index

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