Select a Layer

Find out why the . goes before the /

Moderator: Paul Tuersley

Post Reply
ckelley
Posts: 12
Joined: September 10th, 2004, 1:01 pm

Wondering if it is possible, and if so what is the syntax so I can select a layer in my timeline... I do not need to check if one is already selected, I need to actually have the script select the layer - i.e. - "if X effect is applied, Select the layer" or similar.

TIA,
Chris Kelley
byronnash
Posts: 321
Joined: July 7th, 2004, 2:30 pm
Location: Charlotte, NC
Contact:

You can select a layer either by number or name.

app.project.item(1).layer(1);

I think you might be able to put the layer name instead of the index but I haven't tried that lately. example: app.project.item(1).layer("Solid 3");


Here is an example of how you might set this up in a script.
//sets the project to a variable
var proj = app.project;

//sets the first item in the project to a variable. Assuming it's a comp.
var myComp = proj.item(1);

//sets the 3rd layer to a variable. You could then use the variable to acess the layer in scripting.
var myTextLayer = myComp.layer(3);

Hope that helps.
Paul Tuersley
Posts: 704
Joined: June 5th, 2004, 7:59 am
Location: London, UK

Here's a script that checks all layers in a comp to see if they've got the Levels effect applied. If Levels is found, that layer will become selected in the Timeline window. It sounds like the ".selected = true" bit is what you were looking for.

Paul T

Code: Select all

{ 
	// make sure a comp is selected 
	var activeItem = app.project.activeItem; 
	if (activeItem == null || !(activeItem instanceof CompItem)){ 
		alert("You need to select a comp first."); 

	} else { 
		// create loop to check each layer in comp.
		for (var f = 1; f <= activeItem.numLayers; ++f) {
			currentLayer = activeItem.layer(f);
			alert("Searching layer " + f + ": " + currentLayer.name);

			// search top level properties for "Effects"
			for (var g = 1; g <= currentLayer.numProperties; ++g) {
				if (currentLayer.property(g).name == "Effects") {
					currentEffects = currentLayer.property(g);

					// check each of the effects
					for (var h = 1; h <= currentEffects.numProperties; ++h) {
						thisEffect = currentEffects.property(h);

						// select layer if it contains the Levels effect.
						if (thisEffect.matchName == "ADBE Easy Levels") {
							alert("Levels found on layer: " + currentLayer.name + ".\rSelecting the layer.");
							currentLayer.selected = true;
						}
					}
				}
			}
		}
	}
}
Last edited by Paul Tuersley on March 13th, 2005, 3:04 am, edited 1 time in total.
ckelley
Posts: 12
Joined: September 10th, 2004, 1:01 pm

Thanks alot guys, this should do the trick.

Thanks,
Chris Kelley
Post Reply