Skip to main content
probablykasper
Participant
September 28, 2022
Released

Ability to read text values of dropdowns in expressions

  • September 28, 2022
  • 19 replies
  • 3245 views
It's pretty cumbersome to have expressions work with dropdowns because currently you can only get the number value of a dropdown. Here's an example:

if (thisEffect("dropdown").value == 1) value = 13;
else if (thisEffect("dropdown").value == 2) value = 50;
else if (thisEffect("dropdown").value == 3) value = 100;

Now let's say you use the dropdown to control 12 properties. Then you make some mistake or you decide to change the values of this dropdown. Have fun.

SOLUTION

A solution would be to have a .textValue property of dropdowns. Here's how that would work with the example:

if (thisEffect("dropdown").textValue == "Style 1") value = 13;
else if (thisEffect("dropdown").textValue == "Style 2") value = 50
else if (thisEffect("dropdown").textValue == "Style 3") value = 100

Now the code is a LOT more readable and easier to work with.
    Pinned Reply By JohnColombo17100380

    Hi all,

    Expression access to the text in Dropdown Menu Controls’ Menu property is now available in the release of After Effects 26.0. Details on how to access the selected string or all the strings are documented here: https://helpx.adobe.com/after-effects/using/expression-language-reference.html#dropdown-menu-attributes.

     

    Thank you again for your requests for this feature!

     

    Cheers,

    - John, After Effects Engineering Team

    19 replies

    Participant
    September 28, 2022
    This is a great idea!
    Participating Frequently
    September 28, 2022
    @florian - Thanks for the response, and for helping to clarify why this isn't working. I am no coder, and just dabbling in expressions, so I assumed I was missing something. Clearly I was, so thanks for the heads up! Cheers!
    interactivePixels
    Participating Frequently
    September 28, 2022
    @Seth - the reason that method doesn't work with Expressions is because it is meant for Scripting via Extendscript - it says in the paragraph headline "Scripting support for Dropdown Menu Control"

    While there are many similarities between Scripting and Expressions, there are many things that are unavailable or not fully exposed to the realm of Expressions. Such as setting properties this way, unfortunately!
    Participating Frequently
    September 28, 2022
    Okay, so if you reference this article (https://helpx.adobe.com/after-effects/using/create_dropdowns_using_expressions.html) there is supposedly a way to set the dropdown list array through an expression. This could possibly solve the problem, because you should be able to link to external values within the expression, so you set the "dropdown item#1" value in a given location (which you link to through the expression) and you could then call on that string in other locations, as well as have it update in the dropdown list itself. The problem is, this example, Dropdowneffect = Dropdowneffect.setPropertyParameters(["Monday", "Wednesday", "Friday", "Sunday"]); does not work as described. It says right in the article, "The above statement will edit the dropdown menu to have Monday, Wednesday, Friday, Sunday as the items. The returned property is the updated one and should be used for all further uses." But when you use this, it does not work. Can someone explain how this is meant to work, as it may be a workaround for the time being, or until the textValue option becomes a thing.
    Participant
    September 28, 2022
    the acces to the "textValue" of a dropdownmenu would definitely be a big help.
    For now, I'm afraid it will be the retyping of the list...

    OldDesertLizard
    Known Participant
    September 28, 2022
    Making MOGRTS with calendar-like entries where there are drop-downs for Month and DayOfWeek which I have to populate with values for the human to read; but then I have to re-supply values in the code for the expression to use:

    Months = ["January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December"];
    Months[effect("Month Name")("Menu") - 1];

    I'm good with .textValue or whatever works besides having to make this entry twice. Thanks for considering!
    Participating Frequently
    September 28, 2022
    An even simpler example.

    I want to put some text in a graphic template from a pre-defined list. Currently I would have to set up the dropdown list, then create that same list again in my expressions just to get the text again. If I can access the text value, then I could set that text directly and it would also update if I change the list.

    For that matter, I could also call up a logo to match it by referencing the logo's layer name and checking if it matches the dropdown value. That also would easily copy and paste onto new layers with the same expression, and allow modifying the list without breaking anything.

    Getting the item name from the dropdown is at least as useful as the index number.
    Participant
    September 28, 2022
    I realized this limitation of this new feature as soon as it came out and couldn't believe it.

    I am in a situation now where I have ~40 city names that I'd LOVE to be able to list in the dropdown menu for use in a mogrt. The list selection would trigger the apporopriate city picture to appear and life would be good. Ideally that code would look something like this (in the opacity layer):

    cityA = layer("City Select").effect("Dropdown Menu Control")("Menu").textValue;
    cityB = thisLayer.name;

    if (cityA == cityB) {
    100
    } else {
    0
    }

    INSTEAD I'd have to create 40 variables tying index values to each city name or rely on the layer indexes lining up exactly with the dropdown indexes etc. The ability to access the string values associated with the dropdown menu would allow for much simpler and more flexible coding.

    In regard to the textValue solution, an alternative could be calling to the array i.e. effect("Dropdown Menu").value[0] to call to the index and .value[1] to call to the name/string.
    Participant
    September 28, 2022
    I totally agree with the simplicity of this code and am in dire need of the ability to access the field name, but depending on the backend code of how this expression module was built maybe it still needs the index value from the module so - thisEffect("dropdown").value.text - might be a viable solution also. Although I like the cleanliness of the textValue solution proposed.