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

How to verify if a layer name has a specific substring?

Explorer ,
Aug 12, 2021 Aug 12, 2021

Heey,

 

I'm wondering how to use a substring of a layer name as a condition for an if/else expression.

 

I want to verify that the layer above the layer with the expression, has a specific (part of a) name, and if so, it executes some code.

 

I have added an example. In the example it is only a single word, but I want to be able to apply it to for example "Text Column 1" in such a way that the code will be executed if "Text Column" is in the layer name.

 

I hope my question is clear and that there is someone who can help me.


Thanks in advance

TOPICS
Expressions , Scripting
1.4K
Translate
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 , Aug 12, 2021 Aug 12, 2021

I think your attempt

name.substr(...) = "Heading"

has two problems:

1) you need to use == instead of =

2) the second parameter of substr() is the length of the substring you want to get.

So to compare it to "Heading" which has 7 letters, you should do substr(0,7).

 

Extra tip: If you don't want to find it only at the beginning of the comp name, use the function indexOf:

if(name.indexOf("Heading")>=0){

  // name contains "Heading"

}

Translate
Community Expert ,
Aug 12, 2021 Aug 12, 2021

I think your attempt

name.substr(...) = "Heading"

has two problems:

1) you need to use == instead of =

2) the second parameter of substr() is the length of the substring you want to get.

So to compare it to "Heading" which has 7 letters, you should do substr(0,7).

 

Extra tip: If you don't want to find it only at the beginning of the comp name, use the function indexOf:

if(name.indexOf("Heading")>=0){

  // name contains "Heading"

}

Mathias Möhl - Developer of tools like BeatEdit and Automation Blocks for Premiere Pro and After Effects
Translate
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
Explorer ,
Aug 12, 2021 Aug 12, 2021

I tried to adapt my scripting with the tips you gave me, but I get an error that says: "undefined is not an object".

I added a screenshot of the new code.

Translate
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 ,
Aug 12, 2021 Aug 12, 2021
LATEST

You should run the script in the debugger and see at which line the error occurs exactly. Without a line number, this error message is not helpful.

Mathias Möhl - Developer of tools like BeatEdit and Automation Blocks for Premiere Pro and After Effects
Translate
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