Zack Lovatt

500px Behance Dribbble LinkedIn Pinterest Skype Tumblr Vimeo
October 20, 2012

split() – SourceText from Comp Name

Posted In: expressions

The Idea

Okay, so. You’re working on some lower thirds, and you’ve got your ass-kickin’, award-contendin’ design and animation all worked out and you’re riding your keyframe high only to realize… shit. You’ve got versioning to do. A dozen names and titles, maybe, or region/time zone splits– whatever. You’ve done your pretty-making, and now the grunt work comes in. Open a comp, change the text layer, change the other text layer, duplicate the comp, open it up, change the text layer, change the other text layer, duplicate the comp… Yeah, I’d get tired of it too.

Instead of opening any comp (past initial setup), you can change all the text from your Project Panel and have it propagate into each comp automagically using a handy expression that simplifies the process. Let’s hit it.

We’re going to turn this:
into this:

The Code

We’re going to rely on a method called split(). What this does is break apart a string (some text) into an array, so we can make use of parts of the string independent of others.

As a nice change from my inflated code with odd twists of logic and comments, here’s the expression in all its entirety and glory. This gets applied to the Source Text field of a Text layer." - ")[0]

The Explanation fetches the name of the comp. That’s it– easy enough, and .split() is what pulls it apart.

Looking in our Project panel, you can see our comp name is set up with the dash separating each component. That is, we’ve got Full Name – Title.

We pass the hyphen through the round brackets of split() so it can identify which character(s) will act to split up the text (actually called a delimiter).

So, split(” – “) would give us: “Full Name,” and “Title”– it’s properly fractured the comp name string, as expected.

In order to address either component, we address them in its array like any other property." - ")[0] // results in "Full Name"" - ")[1] // results in "Title"

The Application

If we slot these expressions into the Source Text fields on both our primary and secondary text layers, they’ll now pull their text from the name of the comp, as determined by the array call. From here, we can duplicate the whole composition, change each comp name and end up with a stack of versions with not so much work after all.

Tagged: ,

  1. David Sikes • October 22, 2012

    This is a brilliant solution to a common task that takes up a lot of my time.

    You have done a beautiful job coming up with this. I can't wait to put it to use tomorrow at work on our weekly changing lower-thirds graphics! Reply

    • zack • October 22, 2012

      Thanks, David! Let me know if you have any questions / come across any issues with it! Reply

  2. Andy • October 24, 2012

    Very nice, thanks for the handy tip. Reply

  3. Brad Brown • November 26, 2013

    thanks for the tips!  I use this one almost on daily basis.  Very useful. Reply

  4. Guru Vaidya • April 8, 2014

    Thanks for the tip! This is huge time-saver! Reply

  5. ale • May 14, 2015

    Very nice expression :D Reply

Would you like to share your thoughts?

Leave a Reply