Use text source to change comp name

New Here ,
Mar 21, 2018 Mar 21, 2018

Copy link to clipboard

Copied

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".

TOPICS
Scripting

Views

2.6K

Likes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Mar 22, 2018 Mar 22, 2018

Copy link to clipboard

Copied

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

Likes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Engaged ,
Mar 29, 2018 Mar 29, 2018

Copy link to clipboard

Copied

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?

Likes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Mar 11, 2021 Mar 11, 2021

Copy link to clipboard

Copied

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

Likes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Adobe Community Professional ,
Mar 11, 2021 Mar 11, 2021

Copy link to clipboard

Copied

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

Likes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Dec 11, 2021 Dec 11, 2021

Copy link to clipboard

Copied

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.

Likes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Dec 11, 2021 Dec 11, 2021

Copy link to clipboard

Copied

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

Likes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Adobe Community Professional ,
Dec 12, 2021 Dec 12, 2021

Copy link to clipboard

Copied

LATEST

It might be more useful to actually open up a new thread,  reference this post and provide the full code and info about your project by ways of screenshots. It's not really productive to expect anyone to dig into partial code and expect them to fix any errors when we don't know what actually is going on on your end, no offense.

 

Mylenium

Likes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Adobe Community Professional ,
Mar 11, 2021 Mar 11, 2021

Copy link to clipboard

Copied

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

Likes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines