Skip to main content
brandonb96942845
Inspiring
August 12, 2022
Question

Question: Auto-Populate Dropdown Menu with Layer Names?

  • August 12, 2022
  • 1 reply
  • 1167 views

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?

This topic has been closed for replies.

1 reply

Dan Ebberts
Braniac
August 12, 2022

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.

brandonb96942845
Inspiring
August 12, 2022

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.

brandonb96942845
Inspiring
August 13, 2022

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.


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.