HELP: Resize selected comps + scale position keyframes

Find out why the . goes before the /

Moderator: Paul Tuersley

Post Reply
maximee
Posts: 5
Joined: September 21st, 2007, 10:55 am

Hello everybody.

I've been following these wonderful forums a lot in the past but never been active around here... So here I am :)
In the past I only did a lot of stuff with expressions but now it's time to start scripting.

Here's what I want to do:

Select various comps in my project, run my script and
a. upscale the comp to a specific value
b. rename the upscaled comps
c. adjust all the x/y coordinates of some keyframed expression point controls (in my case the point control is tied to some effects, travelling mattes and a lightsweep)

Objective A and B are working nicely, so far I'm pretty stoked what an easy script can do.
But I can't seem to get part C working. Be aware that this is my first script ever, so things are probably a bit messed up.

I want to have the script check all layers of the selected comps and see if there is a specific layer called "FX_Lightsweep_Controller 03" with an effect called "Lightsweep 03 Position". If this condition is met I want to scale all values of these keyframes accordingly to the overall change in size of the comp. The math behind this is borrowed from here (AWESOME blog, btw!!!)

http://generalspecialist.com/2006/07/ae ... n-path.asp

If the layer is not "FX_Lightsweep_Controller 03" I want it to be centered (i.e. X=compwidth/2, Y=compheight/2)

Here's my script so far, maybe you can help me with this!

var compwidth = prompt("Resize width (pixel):","3200");
var compheight = prompt("Resize height (pixel):","1800");
var suffix = prompt("Comp suffix (leave empty for no suffix):","_HLW");
var mySelection = app.project.selection;
app.beginUndoGroup("resize_selected_comps.jsx");
for (var i = 0; i < mySelection.length; i++)
{
if (mySelection instanceof CompItem)
{
mySelection.name = mySelection.name + suffix;
mySelection.name = mySelection.name.substring(0,31);
var oldHeight = mySelection.height ;
var oldWidth = mySelection.width;
mySelection.height = parseInt(compheight);
mySelection.width =parseInt(compwidth);
var newHeight = mySelection.height ;
var newWidth = mySelection[i].width;
var resizeHeightFactor = (newHeight / oldHeight)*100;
var resizeWidthFactor = (newWidth / oldWidth)*100;

for (var j = 1; j <= mySelection[i].numLayers; j++)
{
var curLayer = mySelection[i].layer(j);
if (curLayer.source.mainSource instanceof SolidSource)
{
curLayer.scale.setValue([resizeWidthFactor , resizeHeightFactor]);

}

if (curLayer.name = "FX_Lightsweep_Controller 03")
{
var myProp = curLayer.effect("FX_Lightsweep_Controller 03")("Lightsweep 03 Position");
for (var k = 1; k <= myProp.numKeys; k++){
var curVal = myProp.keyValue(k);

curVal = curVal / (1 / resizeHeightFactor);

writeLn(curVal[0] + " , " + curVal[1]);

myProp.setValueAtKey(k,curVal);
}

curLayer.position.setValue([1600,900]);



}

}
} }
app.endUndoGroup();


Thanks a lot!
Paul Tuersley
Posts: 704
Joined: June 5th, 2004, 7:59 am
Location: London, UK

The most obvious thing was using "=" (make this equal that) instead of "==" (does this equal that?) here:

Code: Select all

if (curLayer.name = "FX_Lightsweep_Controller 03")
It looks like there's also a mistake where you grab the effect property.

Code: Select all

var myProp = curLayer.effect("FX_Lightsweep_Controller 03")("Lightsweep 03 Position");
I'm guessing it should be:

Code: Select all

var myProp = curLayer.effect("Lightsweep 03 Position")("Point");
I've posted the changes below (wrapped in the [ code ] tag to retain tabbed formatting when viewed on this forum). I've left in the alerts I used to help debug it, but commented out (//) so they don't run.

Code: Select all

var compwidth = prompt("Resize width (pixel):","3200"); 
var compheight = prompt("Resize height (pixel):","1800"); 
var suffix = prompt("Comp suffix (leave empty for no suffix):","_HLW"); 
var mySelection = app.project.selection; 
app.beginUndoGroup("resize_selected_comps.jsx"); 

for (var i = 0; i < mySelection.length; i++) 
{ 
	if (mySelection[i] instanceof CompItem) 
	{ 
		mySelection[i].name = mySelection[i].name + suffix; 
		mySelection[i].name = mySelection[i].name.substring(0,31); 
		var oldHeight = mySelection[i].height ; 
		var oldWidth = mySelection[i].width; 
		mySelection[i].height = parseInt(compheight); 
		mySelection[i].width =parseInt(compwidth); 
		var newHeight = mySelection[i].height ; 
		var newWidth = mySelection[i].width; 
		var resizeHeightFactor = (newHeight / oldHeight)*100; 
		var resizeWidthFactor = (newWidth / oldWidth)*100; 

		for (var j = 1; j <= mySelection[i].numLayers; j++) 
		{ 
			var curLayer = mySelection[i].layer(j); 
			if (curLayer.source.mainSource instanceof SolidSource) 
			{ 
				curLayer.scale.setValue([resizeWidthFactor , resizeHeightFactor]); 
			} 

			if (curLayer.name == "FX_Lightsweep_Controller 03") 
			{ 

			//alert(curLayer.name);

				var myProp = curLayer.effect("Lightsweep 03 Position")("Point"); 

				//alert("name = " + myProp.name + " " + myProp.numKeys + " " + myProp.value[0]);

				for (var k = 1; k <= myProp.numKeys; k++)
				{ 
					var curVal = myProp.keyValue(k); 

					curVal = curVal / (1 / resizeHeightFactor); 

					writeLn(curVal[0] + " , " + curVal[1]); 

					myProp.setValueAtKey(k,curVal); 
				} 

				curLayer.position.setValue([1600,900]); 
			} 
		} 
	}
} 
app.endUndoGroup();


Post Reply