Skip to main content
Participant
March 21, 2018
Question

Use text source to change comp name

  • March 21, 2018
  • 3 replies
  • 5930 views

Is there a script that automatically changes the name of the comp based on a text field in the comp?  Example: LowerThird text (John Doe), comp changes to "John Doe".

This topic has been closed for replies.

3 replies

Justin Taylor-Hyper Brew
Community Expert
Community Expert
March 11, 2021

If by automatically, you mean the comp name will update like an expression, then no this isn't possible. I think a better solution would be to have the LowerThird pull it's text from the Comp Name which you could do with an expression in the sourceText field:

thisComp.name
stib
Inspiring
March 29, 2018

If you select all the comps in your project you can access them with

var myComps = app.project.selection;

that returns an array of all the selected items in the project panel. Since it's an array you can loop through it thus:

for (var i=0; i < myComps.length; i++){

     theComp = myComp;

     //do the stuff

}

Where it says do the stuff is where you put the code for finding the text layer and renaming the comp. Now you have to find the layer in the comp. You get the layers of a comp by using its layers property, which returns the weird data type someone at Adobe dreamed up, a Collection object (seriously, it is indexed from 1 not 0, wtf were they smoking?). You can choose your target layer by name or by index, let's go with name:

var nameLayer = theComp.layers.byName("lower third text or whatever");

Obviously you change the text layer name to the name of your target text layer.

Now we've got the text layer, we have to extract the source text. The source text of a text layer is not just text, it's a TextDocument object, which includes style info as well (It would have been better for everyone if they'd made these normal properties like opacity and scale and so on, but they didn't. That's why you can't animate the font of a text layer, there's no stopwatch). the actual words part of a TextDocument object is its text property. So:

var theText = nameLayer.property("Source Text").value.text;

The next step should be pretty obvious:

theComp.name = theText;

And we're done.

TL;DR

var myComps = app.project.selection;

for (var i=0; i < myComps.length; i++){

     theComp = myComp;

     var nameLayer = theComp.layers.byName("lower third text or whatever");

     var theText = nameLayer.property("Source Text").value.text;

     theComp.name = theText;

}

Save that as a jsx file, e.g. renameCompsFromTextLayerOrWhatevs.jsx. Then edit the name of the target text layer (line 4) to match the name of your text layers, select some comps, and run it from the File>Scripts menu. AE hacker status: levelled up. This script has no error checking, so if you select something that isn't a comp, or doesn't have the right text layer it will probably get grumpy, but whaddayawant for free?

Participant
March 11, 2021

Hey I know I'm a couple years late on this, but this returns an error for me

Justin Taylor-Hyper Brew
Community Expert
Community Expert
March 11, 2021

The code above is an example, you'll need to adjust to work with your project. What error are you getting?

Participant
March 22, 2018

I think you want to say that the text changes the output file name, not the comp name.