-
1. Re: help with change precomp size(weight and height via script)
UQg Mar 24, 2014 5:08 PM (in response to zipkiev)Hi Zipkiev,
if you want to scale the composition and every layer within it, there is a script: Scale Composition.jsx that comes with Ae (in the Scripts folder) that does precisely that.
It scales by a uniform factor using a temporary null object. You can tweak it to scale by a non uniform factor.
But if you only want to preserve the size of layers and adapt their position so that their new position with respect to the new comp center is the same as before, the above script can't help.
In the simplest situation you only need to offset all unparented layers positions by the same amount: [(compNewWidth-compOldWidth)*0.5, (compNewHeigth-compOldHeight)*0.5].
Not sure it will work in all situations though (like 3D with cameras).
You can try this, it might work for you:
// comp is the composition, newWidth and newHeight its new width/heigth
var
dx = (newWidth-comp.width) * 0.5,
dy = (newHeight-comp.height) * 0.5,
layer, n,
p, j,
value;
comp.width = newWidth;
comp.height = newHeight;
for (n=1; n<=comp.numLayers; n++){
layer = comp.layer(n);
if (layer.transform && !layer.parent){
p = layer.transform.position;
if (p.numKeys===0){
value = p.value;
value[0] += dx;
value[1] += dy;
p.setValue(value);
}
else{
for (j=1; j<=p.numKeys; j++){
value = p.keyValue(j);
value[0] += dx;
value[1] += dy;
p.setValueAtKey(j, value);
};
};
};
};
-
2. Re: help with change precomp size(weight and height via script)
zipkiev Mar 25, 2014 7:54 AM (in response to UQg)i want change size of precomp(this need me to get for example 4 pixels alpha on al side of precomp for my task) but not want to change inside comp and layers in that precomp...., also try ask in your example what is 0.5? ( (newWidth-comp.width) * 0.5,)
-
3. Re: help with change precomp size(weight and height via script)
UQg Mar 25, 2014 9:44 AM (in response to zipkiev)Before you apply your changes, the center of the comp has coordinates [comp.width*0.5, comp.height*0.5];
After you apply the changes it has coordinates [newWidth*0.5, newHeight*0.5];
The difference (offset) is [(newWidth-comp.width)*0.5, (newHeight-comp.height)*0.5];
So you offset all layers by that amount to preserve their position relatively to the center of the comp.
I think that for 3D with lights/cameras you'd have to offset also the point of interest by the same amount.
-
4. Re: help with change precomp size(weight and height via script)
zipkiev Mar 26, 2014 3:23 PM (in response to UQg)thx , its help

