Question: Auto-Populate Dropdown Menu with Layer Names?
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?
