Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

Resize Composition to Layers Scale

Explorer ,
Nov 22, 2010 Nov 22, 2010

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


// http://www.the-moron.net


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();

TOPICS
Scripting
3.4K
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct answer

Community Expert , Nov 22, 2010 Nov 22, 2010

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

Translate
Community Expert ,
Nov 22, 2010 Nov 22, 2010

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

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Nov 22, 2010 Nov 22, 2010

Yeeeeessss.

Thanx Dan.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Dec 04, 2010 Dec 04, 2010
LATEST

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

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines