• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
0

How do I apply values to a layer based on a portion of the layer source name?

Contributor ,
Jun 19, 2020 Jun 19, 2020

Copy link to clipboard

Copied

I've written a ScriptUI toolbox to speed up intitial comp setups in our studio.

 

A typical comp might have 3 QuickTime layers in it…

"random_text_RMN.mov"

"random_text_JFK.mov"

"random_text_LBJ.mov"

 

All the text before the last three letters is subject to change. The last three letters (JFK, LBJ, etc) will always be present (and there's about 10 more files that I haven't listed).

 

I have a button that takes the active layer and applies a set of hard coded values to it (for position, scale, and anchor point). It works great, but I had to create a button for every possible QuickTime layer, which makes the toolbox huuuuge. I would like to improve this by having one button that simply reads the last portion of the layer source name then applies a set of unique scale, position, and anchor point values to it. I'm having a little trouble with the syntax though.

 

I assume I need something like…

 

 

 

app.beginUndoGroup("Auto Comp")
         
var character = app.project.activeItem.selectedLayers[0];
     
if (character == item.file.fsName.indexOf("JFK.mov") > -1) {
 character.property("Anchor Point").setValue([2000,3020]);
 character.transform.position.setValue([2126,3695]);
 character.transform.scale.setValue([95,95]);
 }
else if (character == item.file.fsName.indexOf("LBJ.mov") > -1) {
 character.property("Anchor Point").setValue([2000,3600]);
 character.transform.position.setValue([1267,2984]);
 character.transform.scale.setValue([47,47]);
}
app.endUndoGroup();

 

 

 

 but when I click the button with the correct layer selected, nothing happens. I probably did something dumb. 😞

 

Any help would be appreciated! Thanks

TOPICS
Scripting

Views

261

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

correct answers 1 Correct answer

Community Expert , Jun 19, 2020 Jun 19, 2020

I think maybe you just need to check the name of the layer, like this:

 

if (character.name.indexOf("JFK.mov") > -1) {

 

Dan

 

Votes

Translate

Translate
Mentor ,
Jun 19, 2020 Jun 19, 2020

Copy link to clipboard

Copied

I think what you are looking for is the includes() method of strings.

 

*Martin

Votes

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
Contributor ,
Jun 19, 2020 Jun 19, 2020

Copy link to clipboard

Copied

Thanks. I'm fairly new to this. I've edited the post with some updated code, but the syntax is wrong. nothing happens when i click the button with the correct layer selected.

Votes

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 Expert ,
Jun 19, 2020 Jun 19, 2020

Copy link to clipboard

Copied

I think maybe you just need to check the name of the layer, like this:

 

if (character.name.indexOf("JFK.mov") > -1) {

 

Dan

 

Votes

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
Contributor ,
Jun 19, 2020 Jun 19, 2020

Copy link to clipboard

Copied

LATEST

Thanks Dan! Totally worked.

Votes

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