4 Replies Latest reply: Mar 26, 2014 3:23 PM by zipkiev RSS

    help with change precomp size(weight and height  via script)

    zipkiev Community Member

      Hi guys, need help with change precomp size(weight and height  via script), my problem in this... when i change comp size(weight and height) from AE GUI, AE change comp size from center composition, but if i change size of comp from my script it change it from left top corner.... so i need some how change in script center of composition or something like this?

       

       

      now i do change size with this code

      Mycomp.width=Mycomp.width.width+50;

      Mycomp.height=Mycomp.width+50;

        • 1. Re: help with change precomp size(weight and height  via script)
          UQg Community Member

          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 Community Member

            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 Community Member

              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.