Copy link to clipboard
Copied
Hi AEScripters,
could someone tell me why my script doesen't center all my layers?
(I'm trying to build a tiny crop tool)
thnx a lot
:F
Here is my code:
// written by fabiantheblind
function fitCompToLayer()
{
app.beginUndoGroup("fit Comp To Layer");
var activeComp = app.project.activeItem;
var selection = app.project.activeItem.selectedLayers[0];
var myScale = selection.scale.valueAtTime(0.0,false);
var myScaleW = myScale[0];
var myScaleH = myScale[1];
activeComp.width = Math.floor((activeComp.width/100)*myScaleW);
activeComp.height = Math.floor((activeComp.height/100)*myScaleH);
// this doesn't work. but why?
var newWidth = app.project.activeItem.width;
var newHeight = app.project.activeItem.height;
var myLayers = activeComp.layers;
for(var i = 1; i< myLayers.length;i++){
myLayers.position[0] = newWidth / 2;
myLayers.position[1] = newHeight / 2;
}
app.endUndoGroup();
}
fitCompToLayer();
To change the position, you need to use setValue(), like this:
var newWidth = app.project.activeItem.width;
var newHeight = app.project.activeItem.height;
for(var i = 1; i<= activeComp.numLayers;i++){
activeComp.layer(i).position.setValue([newWidth / 2, newHeight / 2]);
}
Dan
Copy link to clipboard
Copied
To change the position, you need to use setValue(), like this:
var newWidth = app.project.activeItem.width;
var newHeight = app.project.activeItem.height;
for(var i = 1; i<= activeComp.numLayers;i++){
activeComp.layer(i).position.setValue([newWidth / 2, newHeight / 2]);
}
Dan
Copy link to clipboard
Copied
Yeeeeessss.
Thanx Dan.
Copy link to clipboard
Copied
haha. Or you make this the easy way like this:
To crop the composition to the region of interest, choose Composition > Crop Comp To Region Of Interest.
http://help.adobe.com/en_US/aftereffects/cs/using/WS3878526689cb91655866c1103906c6dea-7f05a.html