ADOBE AFTER EFFECTS: Forum Expressions Tutorials Creative Cloud

Find and replace text within expressions?

COW Forums : Adobe After Effects Expressions

<< PREVIOUS   •   FAQ   •   VIEW ALL   •   PRINT   •   NEXT >>
Brad Pickford
Find and replace text within expressions?
on Aug 11, 2011 at 2:19:54 pm

Hi everyone, hoping someone could point me in the right direction. I have been searching for a while now and can't seem to crack it.

Basically this is what I am trying to achieve. I have a character rig set up in comp A. Comp A is inside Comp B which has a bunch of controllers that can be animated in Comp B without going back into Comp A all the time (Comp B is where all the elements of the character come together basically). This is working well. My problem is when I copy all elements out of Comp B and paste into a new scene ( we will be placing many of these character rigs into different scenes) all of the expressions that Comp A was referencing in Comp B are now broken. It will be too time consuming to go through and change the code in Comp A to reflect the name of the new comp. I have been looking around for a script that will search and replace text inside an expression but I only found this...

It looks like a nice little script, although it can search and find the code I need to change, it can't go ahead and automatically replace the text I need.

I am not too sure of another way of referencing an expression from a nested comp and make it update automatically when you paste it into a new comp. Any ideas?


Return to posts index

Darby Edelen
Re: Find and replace text within expressions?
on Aug 11, 2011 at 7:10:33 pm

I'm not quite clear on how your rig is set up so I apologize if I say something stupid :)

If your source comp is where things are actually moving, and they're referencing animated positions in a parent comp, then there's really nothing you can do but look for a script to replace text. Even with that script I think it's going to be a PITA though.

If you've set your rig up this when, and you need different animations for your different characters, then there will need to be a different source comp for every character. The source comp will not be able to take input from several different sources at once.

If, however, your source is where you're animating the movement, and the parent comp references that animation to add things to the rig then it becomes somewhat easier:

c = source;

The above applied to a pre-comp gives you a reference to that composition. So you can then do things like:


Which would access the position of the first layer in the child composition.

I hope this has been helpful, if I misunderstood the problem feel free to set me straight :)

Darby Edelen

Return to posts index

Brad Pickford
Re: Find and replace text within expressions?
on Aug 12, 2011 at 12:29:22 am

Hi Darby,
Thanks for your reply. Your idea wasn't quite the solution I needed in this case, it is a bit complicated for me to explain (or I am just not very good at it!) but you certainly gave me an idea that has seemed to work. This is what I came up with...

To change all the references to the new rig location I created a text layer in the child comp "Comp A" and called it "CHANGE TEXT" I then typed out the name of the parent comp "Comp B" in the Source Text. I then added a variable that will get the value of the source text and use it in all of the expressions that reference the animation sliders in the new comp "Comp C". It works! So now all I have to do is change the source text on one layer and all of the expressions change automatically... I have included the code below.

Hope it makes sense,
Thanks again Darby for your help!

nm=comp("Comp A").layer("CHANGE NAME").text.sourceText.value;
comp(nm).layer("Controls").effect("Hat Tilt")("Angle")

Return to posts index

Doog Vandi
Re: Find and replace text within expressions?
on Mar 18, 2014 at 1:46:44 am

Can tell you how you saved my day :)

Return to posts index

<< PREVIOUS   •   VIEW ALL   •   PRINT   •   NEXT >>
© 2019 All Rights Reserved