Activity › Forums › Adobe After Effects Expressions › controlling text from layer name?
-
controlling text from layer name?
Posted by Failsafe on August 28, 2007 at 10:42 pmIs there anyway to have an array of text and update a textfield based on the layers name?
For example, if you have a precomped title that needs many duplicates, all with the same motion and 3d position, can the precomped textfield be updated to pull from an array based on the name generated by duplicating it?
Or is there a better way to handle this? Ideally I don’t want to have to duplicate the same animation and effects over and over for things that will be the same in the end, just different letters…
Failsafe replied 19 years ago 4 Members · 9 Replies -
9 Replies
-
Mike Clasby
August 29, 2007 at 12:34 amThis expression will make the text in the layer say… A through Z, with A being the top layer and Z being the 26th letter down.
After 26 letters you get an “undefined”, get back to me if I’m in the Ball Park and you need it to keep cycling. Go go walk on the beach… low tide.
On source text:
s = “abcdefghijklmnopqrstuvwxyz”;
n = index-1;
s[n]Am I close or way out there?
-
Dan Ebberts
August 29, 2007 at 12:41 amYou could pull text from an array based on the comp name. For example, if your comps were named “Comp 1”, “Comp 2”, etc, you could use something like this to pull text out of the array based on the numeric part of the comp name:
nameArray = [“first comp”, “second comp”, “third comp”, “fourth comp”];
idx = parseInt(thisComp.name.split(” “)[1]);
nameArray[idx – 1]Dan
-
Mike Clasby
August 29, 2007 at 1:42 amI guess I can’t read very well, thanks for the expression, Dan.
-
Kevin Camp
August 29, 2007 at 3:26 pmdo you just want the text field to update by changing the comp’s name?
this as the text source expression will put the comp name as the source text:
thisComp.name
if you duplicate the comp in the project window and change the name of the comp, it will change the source text of that comp.
however, it will only update the from ‘source name’…. i.e. if you duplicate it as a nested comp in another comp and rename that, it will not update the source. at that point, when you rename the nested comp, it is considered renaming a layer (their is a difference between ‘layer name’ and ‘source name’), and i’m not sure you can direct the text source to look a comp’s new ‘layer name’ within another comp.
Kevin Camp
Designer – KCPQ, KMYQ & KRCW -
Failsafe
August 29, 2007 at 4:26 pmThanks for the replies, but not quite there. Dan, it’s close to what you are doing, except I don’t want to have to duplicate the comps themselves in the project window, rather just the layer that contains the comp in the timeline. This way, I can continue to make changes to the animation of the precomp without having to match the animation multiple times.
I took what you sent though and messed with it a bit and got it closer to what I want, but still not perfect.
To explain a bit better, I have Comp 1 which contains the text layer and some circles that animate. I put that into Comp 2 and turn it into a 3d layer, then animate that. Now I’d like to duplicate that 3d layer and change it’s position / animation / etc, but retain the original precomped animation of circles. It works great, but all the text is the same. I need to access the layer name in Comp 2 inside of Comp 1, and set the text based on that. So if i name the layer “Title 1” it pulls the array item 1 to the text in the precomp.
Here’s what I have so far, put onto the source text expression in Comp 1:
a = [‘test 1’, ‘title two’, ‘myTitle’];
a [ parseInt ( comp ( “Comp 2″ ).layer( 1 ).name.split(” “) [ 1 ] ) ];This works, but I still have to explicitly say layer(1). So I can change the text to be whichever I want by renaming the layer in Comp 2, but it still only looks at the first layer in Comp 2 and sets them all.
Is there a way to make layer(1) be dynamic as well? How can I change a variable in the parent comp and make the current layers expression in Comp 2 say something like :
comp( “Comp 1″ ).currentLayerVar = thisComp.layer.name;
Then I could put this into Comp 1’s text expression:
a [ parseInt ( thisComp.currentLayerVar.split(” “) [ 1 ] ) ]; -
Dan Ebberts
August 29, 2007 at 4:44 pmAs far as I know, there’s no way for a an expression to access info about its comp’s parent comp except by using the name of the comp. It makes sense, really, if you think about it. A particular precomp can be nested into any number of parent comps, and once a precomp frame is rendered, that image will be cached and used in any parent comps. So the image can’t be different (e.g., different text) from one instance to the next. That’s the way I understand it anyway.
Dan
-
Failsafe
August 29, 2007 at 4:58 pmI see what you mean about caching and it makes sense, but is a bummer nonetheless.
Is the only way then to precomp just the circles animating, then put that into a new comp and add text, duplicate it 6 times in the project window, then bring those into Comp 2 individually?
This will still allow my to animate the circles once and update everywhere if needed, but still have to edit 6 separate comps if I add any animation to the text itself.
-
Dan Ebberts
August 29, 2007 at 5:30 pmThat should work. I can’t think of a better way, unless you plan to do a lot of this and want to dive into scripting.
Dan
-
Failsafe
August 29, 2007 at 5:33 pmI know a fair bit of code, javascript and flash AS3. Expression scripting doesn’t seem very difficult, though the concepts and syntax are a bit different.
For example, the way I am trying to do this is the same way I would handle it in flash, but the text fields could even be pulled from XML or a database, and clickable.
If you can think of a better way, I won’t shy away from the code. =)
Reply to this Discussion! Login or Sign Up