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

Question: Auto-Populate Dropdown Menu with Layer Names?

Participant ,
Aug 12, 2022 Aug 12, 2022

Copy link to clipboard

Copied

Greetings all,

 

Was looking on Google to see if there was a solution to an incresingly-complicated problem I'm running into. Basically, I'm trying to get a dropdown menu to auto-populate with the names of layers in the comp, starting with a specific layer (so index + x). By this, I don't mean the values, just the names. I've got a separate solution for the actual values.

 

Anyway, I came across what I thought was a partial solution, but it's not working, so I wanted to see if anyone here might've cracked this one.

 

This is the code sample I came across (the poster says that this actually does two things, auto-populates the dropdown and then disables all layers except the one that's selected; I don't need the second half but I don't know programming well enough to be able to tell which part to pull out):

var myWin = new Window("palette", "Drop down list", undefined);
var proj = app.project;
var awayComp = proj.item(2);
var homeComp = proj.item(3);
var myList = new Array();

for(var i=1; i <= awayComp.numLayers; i++){
myList[myList.length] = awayComp.layer(i).name;
}


var groupOne = myWin.add("group", undefined, "GroupOne");
var dd = groupOne.add("dropdownlist", undefined, myList);
dd.selection = 0;



dd.onChange = function() {

for(var i = 1; i < awayComp.layers.length +1;i++){
//Hides all visible layers
awayComp.layer(i).enabled = awayComp.layers.enable = false;
// check name
if(awayComp.layers.name == ??????){ //I dont know what to type here to connect with the dropdown selected team
// turn into opposite
awayComp.layers.enabled = !awayComp.layers.enabled;
}
}
};



myWin.center();
myWin.show();

If anyone is wondering, this code sample came from here: https://aenhancers.com/viewtopic.php?t=2421

As for the actual values of the dropdown, I've covered that in a slightly different way:

var x = effect("Dropdown Menu Control")("Menu").value;
var y = 8;
titles = [thisComp.layer(index+y).name,
  thisComp.layer(index+y+1).name,
  thisComp.layer(index+y+2).name,
  thisComp.layer(index+y+3).name,
  thisComp.layer(index+y+4).name,
  thisComp.layer(index+y+5).name,
  thisComp.layer(index+y+6).name,
  thisComp.layer(index+y+7).name,
  thisComp.layer(index+y+8).name,
  thisComp.layer(index+y+9).name,
  thisComp.layer(index+y+10).name,
  thisComp.layer(index+y+11).name,
  thisComp.layer(index+y+12).name,
  thisComp.layer(index+y+13).name,
  thisComp.layer(index+y+14).name,
  thisComp.layer(index+y+15).name,
  thisComp.layer(index+y+16).name,
  thisComp.layer(index+y+17).name,
  thisComp.layer(index+y+18).name,
  thisComp.layer(index+y+19).name,
  thisComp.layer(index+y+20).name,
  thisComp.layer(index+y+21).name,
  thisComp.layer(index+y+22).name,
  thisComp.layer(index+y+22).name,
  thisComp.layer(index+y+23).name,
  thisComp.layer(index+y+24).name,
  thisComp.layer(index+y+25).name,
  thisComp.layer(index+y+26).name,
  thisComp.layer(index+y+27).name,
  thisComp.layer(index+y+28).name,	
  thisComp.layer(index+y+29).name,
  thisComp.layer(index+y+30).name,
  thisComp.layer(index+y+31).name,
  thisComp.layer(index+y+32).name,
  thisComp.layer(index+y+33).name,
  thisComp.layer(index+y+34).name,
  thisComp.layer(index+y+35).name,
  thisComp.layer(index+y+36).name,
  thisComp.layer(index+y+37).name,
  thisComp.layer(index+y+38).name,
  thisComp.layer(index+y+39).name,
  thisComp.layer(index+y+40).name,
  thisComp.layer(index+y+41).name,
  thisComp.layer(index+y+42).name,
  thisComp.layer(index+y+43).name,
  thisComp.layer(index+y+44).name,
  thisComp.layer(index+y+45).name,
  thisComp.layer(index+y+46).name,
  thisComp.layer(index+y+47).name,
  thisComp.layer(index+y+48).name,
  thisComp.layer(index+y+49).name];
titles[x-1]

You can see how many layers we're already dealing with, and the situation I'm running into is that I'm needing to add layouts on the fly, but every time I do I have to go through and manually change the names in the Dropdown Menu effect (when you click the "Edit" button) so I know which layout I'm selecting. I've made it easier when it comes to the actual values of the dropdown, all I have to do is add one more line and increase the value of Y by one more.

 

So two questions:

1)  Is there a way to make the process of adding names to the dropdown any easier?

2)  In the second code sample, is there a way to add a recursive statement to each line so that I don't have to specify "Y+1," "Y+2" each time, but rather have it automatically increase by one on each line?

TOPICS
Expressions , How to , Scripting

Views

110

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 Expert ,
Aug 12, 2022 Aug 12, 2022

Copy link to clipboard

Copied

I'm confused. Are you trying to manipulate a dropdown list in a script UI, or a dropdown menu expression control? A more thorough explanation of exactly what you're trying to do (rather than the code you're using) would be helpful.

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
Participant ,
Aug 12, 2022 Aug 12, 2022

Copy link to clipboard

Copied

So remember the super AE comp we built? I'm trying to streamline updating that.

 

The first objective is to manipulate the dropdown list in the script UI, by populating it with layer names automatically instead of doing it manually like I have to now. Currently, what I have to do to make updates to the script UI list is go to the layer with the dropdown effect, click "Edit," and then manually type in the layer names (with each layer name corresponding to a specific layout). Obviously when we've got 50 layers, that can get tedious, so I'm trying to streamline that if I can.

In simple terms, what I want the script UI to do is pull the names of all the layers that correspond to layouts (but those don't start until a few layers removed from the layer with the dropdown itself, hence why I said "index + x," where X is the number of non-layout layers between the dropdown and the first layout).

For the second half, remember how you came up with the expression to add to the SourceText property of the dropdown layer, so that the input sources would know which layout to follow? I've got to update that manually too, but I want to try to circumvent having to manually update that as well by referencing layer names instead of manually entering the layer names into the expression.

Essentially, I'm looking for both the SourceText expression and the script UI to do the same thing: beginning with the layer 8 layers down from the dropdown layer itself, pull the layer names and insert them into the dropdown list, one in the script UI so I can see the name of the layout I'm selecting, and the other in the expression to actually select it. In algorithmic terms:

Dropdown List Entry 1 = thisComp.layer(index+8).name;

Dropdown List Entry 2 = thisComp.layer(index+9).name;

And so on for however many layers there are. (I know I'll have to manually add a line anytime I add a layout.)

 

The idea is to keep from having to do manual updates every time I need to add a layout to the mix, since as I'm finding out this approach opens up a lot of new possibilities I hadn't anticipated when we started. This solution would let me add layouts anytime I needed to without having to go through the painful process of updating the list, and keep the entries in the order that they appear in the comp. Hopefully all this makes sense but if not let me know.

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 Expert ,
Aug 12, 2022 Aug 12, 2022

Copy link to clipboard

Copied

It probably makes sense, but I can't really picture it. My hunch is that there's a better way, but I don't really see the big picture.

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
Participant ,
Aug 12, 2022 Aug 12, 2022

Copy link to clipboard

Copied

Let me try again.

So when we set up the Dropdown Menu effect in the AEP we built, we set it up to have two pieces to it: the dropdown menu effect itself, and a series of values parented to the SourceText layer on the dropdown menu itself.

To make it work the way we wanted it, the first thing we did was set up the SourceText piece, which changes based on the numeric value from the dropdown menu itself. To do that we wrote an expression that had a series of values written into it--each of those values corresponded to the name of a layer in the composition.

Then, to make life easy on myself, I added the same layer names, in the same order, to the Dropdown Menu effect itself.

All well and good, except for the fact that anytime I need to add a layer to the comp, I have to go in and manually add an entry to the expression, and then I also have to go in and add an entry to the Dropdown Menu effect itself. (This one is no fun because I have to add it, and then drag it up so that the order of the entries matches the order of the layers in the comp.)

What I'm looking to do is two things:

1)  For the expression, instead of having to go in and manually add values anytime I need to add one, I want the expression (applied to SourceText on the dropdown menu layer) to automatically pull the names of all the layout layers in the comp. These don't start until a few layers down from the dropdown layer itself, so it would need to be able to start looking a certain number of layers down, and then pull the name of each layer one at a time to build a list. (Basically it's doing automatically what we did by hand in the expression you pulled together.)

2)  Because the layers are in a particular order, I also want to find a way to make the Dropdown Menu effect itself (I don't know if that's a Script UI or just effect options) do the same to populate the list of values that go with the numbers. (I think by default it just says "Item 1" or something like that.)

The big picture is this: each time I need to make an update to add a value, it's a pain in the neck because I've got to go in and do everything by hand. I have to go to the expression, and add the name of the layer to the expression in the right place, and then go into the effect options and add it a second time, dragging it up to where it goes. If I have to add multiple layouts, it gets a lot more complicated. So all I'm looking to do is get the layer to pull the names of the layers and put them into the expression, in the order they appear in the comp; then I want to do likewise to the values in the effect itself, so I don't have to go through and do it by hand each time.

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 Expert ,
Aug 12, 2022 Aug 12, 2022

Copy link to clipboard

Copied

I can tell you how I'd approach it. I think I'd ditch the idea of a script with a UI and just create a script that assumes that when it runs, you have the comp open and the layers that you want to show up in the dropdown menu (and the text) selected. It finds the dropdown menu layer by name ("Dropdown Menu"), then it creates an array of selected layer names. It uses the array to build the parameter list for the dropdown menu, and also to build a  new version of the source text expression. I could probably hammer something like that out in about an hour or so--it'll take you longer if you haven't done much scripting, but it shouldn't be too tough and would definitely be good experience.

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
Participant ,
Aug 13, 2022 Aug 13, 2022

Copy link to clipboard

Copied

LATEST

I've never actually done any scripting at all (I've been trying to learn from all the help you've been giving me but I'm still barely able to understand some of the back ends of what we've pulled together), so honestly I wouldn't even know where to begin.

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
Participant ,
Aug 12, 2022 Aug 12, 2022

Copy link to clipboard

Copied

If it would help this is the AfterFX project file I'm working with. Like you said before, it's a pretty complicated piece of work, but when you see it it'll probably make more sense.

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