Skip to main content
New Participant
March 21, 2018
Question

Use text source to change comp name

  • March 21, 2018
  • 3 replies
  • 5913 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
Braniac
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?

New Participant
March 11, 2021

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

Trocalex
New Participant
December 12, 2021

Hi Stib, I REALLY appreciate your script suggestion.

Tried it too but got this error: Unable to execute script at line 3. myComp is undefined

Only thing I replaced was the "lower third text or whatever" for the name of my text layer "ID" that contains a serial number as a source text.

I also tried without avail to use tokens so the render names could be named after the source text of the first layer of each comp but wasn't able to find any combination of words that could pull that out.


I don't mind if it doesn't work automatically. I would be more than happy if I can run the script once for each batch.

I also know that there's a easy way to do it the other way around: Comp Name > Text Layer but in my case we're talking about a long list of comps that would be auto filled from a .csv so the other way would defeat the purpose of using an external list.  Thanks

New Participant
March 22, 2018

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