Select Layers by name

Find out why the . goes before the /

Moderator: Paul Tuersley

Post Reply
User avatar
stakker
Posts: 3
Joined: June 9th, 2008, 4:31 am

I want to make a script that adjusts the levels of a layer with a specific name...

My plan was to do it this way, but it doesn't work, because "undefined is not an object" ??!

Code: Select all

numitems = app.project.numItems;
		for(var i=1; i<=numitems; i++)
		{
			if(app.project.item(i).name == "left.psd")
			{
				var leftLayer = app.project.item(i);
				theEffect = leftLayer.Effects.addProperty("ADBE Easy Levels");
				theEffect.property("ADBE Easy Levels-0001").setValue(3);
				theEffect.property("ADBE Easy Levels-0007").setValue(0);
			}
			else if(app.project.item(i).name == "right.psd")
			{
				var rightLayer = app.project.item(i);
				theEffect = rightLayer.Effects.addProperty("ADBE Easy Levels");
				theEffect.property("ADBE Easy Levels-0001").setValue(2);
				theEffect.property("ADBE Easy Levels-0007").setValue(0);
			}
		}
cheerz stakker
Paul Tuersley
Posts: 704
Joined: June 5th, 2004, 7:59 am
Location: London, UK

The problem is that you're effectively trying to add an effect to a footage item in the project panel, which clearly isn't possible. If the footage is being used in a comp/comps, you need to find which comps it's used in, then check through the layers until you find the right one, then apply the effect to that layer.

Code: Select all

numitems = app.project.numItems;
alert("There are " + numitems + " items in the project");
	for(var i=1; i<=numitems; i++) {
		alert("Checking if item " + i + " - " + app.project.item(i).name + " is left.psd" );
		if (app.project.item(i).name == "left.psd") {
			var leftArray = app.project.item(i).usedIn;
			if (leftArray == "") {
				alert("left.psd is not used");
			} else {
				alert("Found left.psd. It's used in " + leftArray.length + " comps.");
				for (var j = 0; j < leftArray.length; j++) {
					var theComp = leftArray[j];
					alert("Checking " + theComp.name + " comp which has " + theComp.numLayers + " layers");
					
					for (k =1; k <= theComp.numLayers; k++) {

						if (theComp.layer(k).source.name == "left.psd") {
							alert("Found left.psd. It's layer " + k + " in " + theComp.name + ". Adding effect.");
							var leftLayer = theComp.layer(k);
							theEffect = leftLayer.Effects.addProperty("ADBE Easy Levels");
							theEffect.property("ADBE Easy Levels-0001").setValue(3);
							theEffect.property("ADBE Easy Levels-0007").setValue(0);
						}						
					}
				}
			}
		}
		else if(app.project.item(i).name == "right.psd") {
			alert("I found right.psd too!");
		}
	}
User avatar
stakker
Posts: 3
Joined: June 9th, 2008, 4:31 am

Yo bro! thanks! I'm going to try it this way!
User avatar
stakker
Posts: 3
Joined: June 9th, 2008, 4:31 am

Now i got the problem, that i don't know how to change the blending-modes of a layer per script... could anyone please help me, or tell me a page/book where all these attributes are listed?!

thanx, stakker
Paul Tuersley
Posts: 704
Joined: June 5th, 2004, 7:59 am
Location: London, UK

The blendingMode attribute on page 42 of the CS3 Scripting Guide. Here's a code example:

Code: Select all

// if the left layer has a Normal blending mode, change it to the Add mode
if (leftLayer.blendingMode == BlendingMode.NORMAL) {
	leftLayer.blendingMode = BlendingMode.ADD;
}
Post Reply