Dropdown Menu listing all layers in active comp

Find out why the . goes before the /

Moderator: Paul Tuersley

Post Reply
swink85
Posts: 13
Joined: January 5th, 2010, 1:37 am

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.
Paul Tuersley
Posts: 704
Joined: June 5th, 2004, 7:59 am
Location: London, UK

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);
		}
	}
			
}
Post Reply