How To Change The Text In The Comp From The Comp Name in After Effects

In this post, I will show you how to change the text inside of the composition from the composition name. So without any further ado, let’s dive right in!

Alright, we are in After Effects. First, let me show you what we will be creating. Right now I have a composition FIRST LASTNAME, TITLE GOES HERE

Composition in After Effects

I have the NAME text.

Name Text in After Effects

And I also have a TITLE1 text.

Title Text in After Effects

Now let me show you how we can change the NAME and the TITLE1 text directly from the name of my composition inside of my project panel.

Changing the name and title from the composition in After Effects

So right now, I am going to select the FIRST LASTNAME, TITLE GOES HERE composition, hit enter and type SERGEI PROKHNEVSKIY.

Next, I will type a comma in the same line and everything that I type after the comma will automatically be placed in the TITLE1 text under the NAME text.

I will go ahead and type UKRAMEDIA.COM after the comma. So now if I let go, you should see SERGEI PROKHNEVSKIY and the TITLE1 should be changed to UKRAMEDIA.COM. That’s pretty cool, right?

Typing in Composition in After Effects

You might be asking, how is that useful? Well, let me show you a quick example.

Right now we can change the name of our lower third straight from our composition name. So if I select the composition name and duplicate it with the duplicate keyboard shortcut CTRL+D (CMD+D on a Mac).

Duplicate Keyboard Shortcut for After Effects

Then I can double click on this duplicate composition and type another name. Let’s use ELIJAH PATRICK for this example and the TITLE1 will be MOTION GRAPHIC DESIGNER. If I let go, everything should change as well.

Elijah Patrick After Effects

You can easily duplicate things, change the NAME/TITLE1, and everything will be adjusted for you on the fly with ease. This can speed up your workflow on your next project in After Effects. Now let me show you how to set this up.

Step 1: Select Source Text

First, I am going to go inside of my NAME layer and select the Source Text.

Source Text in After Effects

Step 2: Solo Source Text

Next, hit S twice to solo the Source Text.

Solo keyboard shortcut in After Effects

Let’s also solo the TITLE1 Source Text while we are at it.

Solo Title Text Source in After Effects

Step 3: Activate the NAME Source Text Expression

Let’s active the Source Text expressions by ALT+Left Mouse Click on the Source Text stopwatch icon or OPT+Left Mouse Click on a Mac.

Activate expressions inside of Source Text in After Effects

Step 4: Define a Variable

Now let’s define a variable inside of the white text box. I am going to say compName, you are going to be SERGEI PROKHNEVSKIY, UKRAMEDIA.COM composition by pick-whipping to it like so:

Pick Whip After Effects to Composition

I also want the name of that composition, so I am going to say .name. Our expression should look like this:

compName = comp(“SERGEI PROKHNEVSKIY, UKRAMEDIA.COM”).name

Step 5: substring() Method

Next, I’ll do a very simple expression. I am going to say compName.  , so I am referring to our SERGEI PROKHNEVSKIY, UKRAMEDIA.COM composition. And after that, I am going to use a method called substring().

compName = comp(“SERGEI PROKHNEVSKIY, UKRAMEDIA.COM”).name

compName.substring()

Substring extracts characters from the text. So I am referring to the SERGEI PROKHNEVSKIY, UKRAMEDIA.COM text and I want certain characters.

So I am going to say that I want characters starting at 0 and ending at 8.

compName = comp(“SERGEI PROKHNEVSKIY, UKRAMEDIA.COM”).name

compName.substring(0,8)

If I let go right now, it is going to show me all the characters starting at index 0 and ending at 8. Now even though it said 8 and that’s supposed to be the letter R, but it’s showing me P.

Index in After Effects

The reason why it is showing P instead of R is because it doesn’t include the very last index, which is important to point out but that’s not exactly what we want. We want the first name and the last name, so to include both of these, I’m going to use the comma here as a triggering point and then I’ll say: include all the texts starting at 0 up to the comma.

Step 6: indexOf Method

To do that, we’ll use indexOf, which is another JavaScript method. So I’m going to say compName.indexOf() and inside the quotation, I’m gonna say comma, like so:

compName.substring(0,compName.indexOf(“,”))

Basically, what indexOf does, is it grabs the index of whatever letter that you’re telling it to be. So in our case, I said grab the index of this SERGEI PROKHNEVSKIY comma and it’s going to give me the index number of that comma.

Now it will go from 0 to that index. The cool thing is that the index can change, so it will give me that index the whole time.

Now if I let go right now, you can see that it does include my first and last name. So it’s pretty easy to set up.

Setting up indexOf in After Effects

Now let’s do the same thing for  TITLE1. I’m going to ALT+Left Mouse Click (OPT+Left Mouse Click on a Mac) the stopwatch icon to active expressions.

Alt click on the stopwatch icon in After Effects to activate the expression

Next, I’ll type compName and I’ll say you’ll be this composition SERGEI PROKHNEVSKIY, UKRAMEDIA.COM by pick-whipping to it like so:

Pick Whip to composition in After Effects

I want the name of that so that’s why I say .name:

compName = comp(“SERGEI PROKHNEVSKIY, UKRAMEDIA.COM”).name;

and next, we’ll type the exact same thing again:

compName.substring()

Inside of the (), instead of going from 0 to the comma as we did in the NAME text example, I’m going to start at the comma and say compName.indexOf(“,”). It should look like this:

compName = comp(“SERGEI PROKHNEVSKIY, UKRAMEDIA.COM”).name;

compName.substring(compName.indexOf(“,”))

If I let go of it right now, you can see that the text will start at my index and it is going to keep going all the way.

compName index in After Effects

That’s why I didn’t include the ending index because if you don’t include it, it will just keep going.

No ending index in After Effects expression

Now, the only problem is that it is including our index.

Including index in After Effects

As you can see from the picture above, it is including the comma and extra space.

To get rid of these two characters we  just have to say plus two at the end like so:

compName = comp(“SERGEI PROKHNEVSKIY, UKRAMEDIA.COM”).name;

compName.substring(compName.indexOf(“,”)+2)

So it is going to grab that index and it is going to add two more to it. That should fix it.

No extra characters in After Effects

So right now if we change our composition name to say ELIJAH PATRICK, MOTION GRAPHICS DESIGNER, you can see that it is easily adjusting everything. It is pretty easy to set up.

I hope you found this post useful. If you would like to learn more about Expression and how it can speed up your workflow in After Effects, then check out my Learn After Effects Expressions Course.

About the author:

Sergei Prokhnevskiy

Sergei Prokhnevskiy is a Charlotte, NC based motion graphics designer, an online tutor, an entrepreneur, and Adobe MAX Master Speaker. Sergei is known for his quick and practical After Effects tips and tricks on YouTube, where he generated well over 6 million views on his tutorials. He has authored an online video course on After Effects Expressions and developed scripts for After Effects. He is also a former senior motion graphics designer at Fox Sports where he worked on graphics for NFL, Super Bowl, MLB, World Series, College Football, NASCAR, Women’s World Cup, and NASCAR Race Hub. He is very passionate about learning and teaching others.

5 FREE TIME-SAVING TOOLS

Over 100,000 downloads & counting!

These 5 After Effects tools will seriously speed up your workflow and save you hours of wasted time. More than that, they could be the difference between being able to complete a project on time or not!