HELP: Resize selected comps + scale position keyframes
Posted: September 24th, 2007, 5:53 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!
Thanks a lot!
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!