Page 1 of 1

Dropdown Menu listing all layers in active comp

Posted: February 26th, 2011, 12:49 pm
by swink85
Hi,

This request seems simple but I haven't seen an example of what I am looking for anywhere. I have a UI where I want to create a dropdown box listing all the layers in the comp. I think I know how to get the dropdown created, but I am not sure how to generate an array of all the layer names.

Re: Dropdown Menu listing all layers in active comp

Posted: March 4th, 2011, 3:55 am
by Paul Tuersley
Here's some code that won't work on its own, but should give you some ideas. The layerNameArray stuff shows how you could create an array of layer names. The palette stuff shows how you might implement adding items to a drop down. I imagine that this is something that will need refreshing, so you could first do a removeAll to clear out the list, then loop through the layers adding a new list item for each name.

Code: Select all

{
	var activeItem = app.project.activeItem;	
	if (activeItem != null && activeItem instanceof CompItem) {
		
		var layerNameArray = new Array();	
		palette.dropDown.removeAll()	
		
		for (var x = 1; x <= activeItem.numLayers; x++) {
			//$.writeln(activeItem.layer(x).name);	
			layerNameArray.push(activeItem.layer(x).name);
			palette.dropDown.add("item", activeItem.layer(x).name);
		}
	}
			
}