Auto-Set Value by Comp Name in After Effects

To change any value based on the comp’s name we can use .indexOf() function to check if a specific keyword exists within the composition name.

For example, here is how to change the value of a dropdown menu:

Expression

  1. Add a Dropdown Menu Control to the layer (Effect > Expression Controls > Dropdown Menu Control).
  2. Customize the dropdown options to match the different keywords or parts of the comp name you want to check for.
  3. Apply the following expression to the Dropdown Menu Control:
JavaScript
compName = thisComp.name; // Gets the name of the current composition

// Check if part of the comp name matches a keyword
compName.indexOf("Intro") != -1 ? 1 : // If "Intro" is found, set to first option
compName.indexOf("Main") != -1 ? 2 :  // If "Main" is found, set to second option
compName.indexOf("Outro") != -1 ? 3 : // If "Outro" is found, set to third option
1; // Default to first option if no match

Explanation

  • compName.indexOf("Intro") != -1: Checks if "Intro" is a part of the composition name.
    • If found (index is not -1), it returns 1 (the first dropdown option).
    • If not found (index is -1), it moves to the next check.
  • Other Keywords: Similarly, "Main" and "Outro" keywords are checked and set to corresponding dropdown values if present.
  • Default Option: If none of the keywords are found, it defaults to 1.

This expression will change the dropdown menu dynamically based on whether part of the composition’s name matches one of the specified keywords.

Leave a Reply

Your email address will not be published. Required fields are marked *