ADOBE AFTER EFFECTS: Forum Expressions Tutorials Creative Cloud

How to replace one line of code in multiple layers?!

COW Forums : Adobe After Effects Expressions

<< PREVIOUS   •   FAQ   •   VIEW ALL   •   PRINT   •   NEXT >>
Greta Sennekamp
How to replace one line of code in multiple layers?!
on Apr 18, 2018 at 1:42:32 pm

Hey everyone,

is there a way to exchange for example one word in my expression with another but in multiple layers? i have a little (tiny tiny) bit of experience in coding and when i used "sublime" i could look for the same word in a hole file an change them all together.

i hope you get what i tried to explain.


Return to posts index

Scott McGee
Re: How to replace one line of code in multiple layers?!
on Apr 19, 2018 at 9:42:35 am

I create a expression control comp and keep all my expression layers in there and tie them us using something like this to the multiple layers

eval(comp("1 - Control Center").layer("City").text.sourceText.toString())

then if I need to make any changes I go to my expression control comp and make the alterations there, once updated. this updates all the layers it's need for.

Hope that helps


Return to posts index

James Ronan
Re: How to replace one line of code in multiple layers?!
on Apr 19, 2018 at 12:19:21 pm

This sounded quite like an interesting task so thought I'd give it ago. Bit rough, and haven't done a lot of testing but it should replace every instance of that word, project wide.

Make sure the value for the oldWord variable has '/' and '/g' before and after it so that it doesn't only change the first instance of the word per expression.

var oldWord = /old/g;
var newWord = "new";

app.beginUndoGroup("Expression Swap");

for (var a = 1; a <= app.project.numItems; a++) {
if (app.project.item(a) instanceof CompItem) {

for (var b = 1; b <= app.project.item(a).layers.length; b++) {
scanPropGroupProperties(app.project.item(a).layer(b));

} // end of layer loop
} // end of check if comp item
} // end of comp loop

app.endUndoGroup();

function scanPropGroupProperties(propGroup) {
var c, prop;

// Iterate over the specified property group's properties
for (c = 1; c <= propGroup.numProperties; c++) {
prop = propGroup.property(c);
if (prop.propertyType === PropertyType.PROPERTY) // Found a property
{

expressionFix(prop);

} else if ((prop.propertyType === PropertyType.INDEXED_GROUP) || (prop.propertyType === PropertyType.NAMED_GROUP)) {
// Found an indexed or named group, so check its nested properties
scanPropGroupProperties(prop);
}
}
}

function expressionFix(prop) {
if (prop.canSetExpression === true) {
if (prop.expressionEnabled === true) {

var curExp = prop.expression;
curExp = curExp.replace(oldWord, newWord);
prop.expression = curExp // updates old expression with new words
}
}
}


I used the recursive property function from redefinery to loop through the properties: http://www.redefinery.com/ae/fundamentals/properties/


Return to posts index


Greta Senne
Re: How to replace one line of code in multiple layers?!
on Apr 19, 2018 at 2:47:12 pm

Thank you very much! I currently have no time today to try out both of your ways - but i cant wait!
i´ll let you know if i was successfull


Return to posts index

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