レイヤーの位置、スケール、回転、不透明度を設定する

トランスフォームプロパティのそれぞれのプロパティにsetValueメソッドを使って、新しい値を渡す。

プロパティの中でも書き方が多様なので、それぞれについて解説する

1

このプロパティのいくつかは、トランスフォームプロパティとするか、レイヤープロパティとするかを選べる

var target = app.project.item(1).layer(1);

target.transform.position.setValue([0,0]);

target.transform.scale.setValue([50,50]);

target.transform.opacity.setValue(50);

本来なら上記のようにレイヤーのトランスフォームプロパティの位置プロパティとなるのだが、

いくつかのプロパティはトランスフォームのプロパティとしてではなく、レイヤーのプロパティとして存在している、

上記は以下のように書ける

var target = app.project.item(1).layer(1);

target.position.setValue([0,0]);

target.scale.setValue([50,50]);

target.opacity.setValue(50);

レイヤープロパティとして存在するトランスフォームプロパティは以下

anchorPoint

position

scale

orientation

rotation

rotationZ

opacity

一文字目は大文字でも良い(Position)がとくにそうする必要はない

rotationとrotationZは同じ。3DレイヤーになっていなくてもrotationZで値を渡せるorientationは3Dレイヤーの時のみ

それ以外は省略できない

2DレイヤーでもsetValueは3次元の値を渡しても良い

2

それ以外のプロパティと書き方

target.transform('アンカーポイント').setValue([10,10]);

target.transform('ADBE Orientation').setValue([10.0,20.1,30.5]);

target.transform.scale.setValue([100,100,100]);

この表の真ん中のプロパティ名はドット演算子でそのまま使えるので、こちらを利用するとよいかも

日本語名や、間に空白のある名前はクウォートで囲んで、引数として渡さなければならないのだが、

この真中の名前はドット演算子でつなげることができ、日本語版AEでも問題なく動作する

target.transform('アンカーポイント').setValue([10,10]);

                                ↓

target.transform.anchorPoint.setValue([10,10]);

target.transform('ADBE Rotate X').setValue(45);

                                ↓

target.transform.xRotation.setValue(45);

これならtransformまでを参照変数にしてしまえばよいので

var targetLayer = app.project.item(1).layer(1)

var targetTransform = targetLayer.transform;

targetTransform.xRotation.setValue(120);

などとすることができる

3DレイヤーになってないものへのX,Y回転や

次元の分割をしていないものへのX位置、Y位置、Z位置へプロパティを設定するとエラーがでるので注意

その際は、回転と方向はレイヤーのプロパティのthreeDLayerを、

X位置などは位置プロパティのdimensionsSeparatedを調べるとtrue,falseが返ってくるので、それを利用するとよい

3

通し番号を使う

これはプロパティ全般にいえることだが、すべて通し番号でアクセスできる

ただしバージョンによるプロパティの追加、廃止があるので、通し番号はバージョンによって異なる。

AE7/CS4のトランスフォームプロパティの番号は5なので

var target = app.project.item(1).layer(1);

の場合

target(5)はtarget.transformと同じ意味

上記表のプロパティのenumを見ると、スケールは6なので

target(5)(6).setValue([100,100]);

とすると、スケールがX,Yとも100%になる

X位置だけ取り出すには

target(5)(2).value[0];

AE4から次元の分割ができるようになっているのに、その番号が若い番号になっているのでCS3以前では通し番号の数値が違うはず。

なのでこの書き方はあまりおすすめできない

わかりづらいし

まとめ

var targetComp = app.project.item(1);

var targetLayer = targetComp.layer(1)

var targetTransform = targetLayer.transform;

の場合の例

アンカーポイントを設定する

targetTransform.anchorPoint.setValue([500,500,0]);

アンカーポイントを得る

var ac = targetTransform.anchorPoint.value;

位置を設定する

targetTransform.position.setValue([100,100,100]);

位置コンポの真ん中にする

targetTransform.position.setValue([targetComp.width/2, targetComp,height/2]);

スケールを設定する

targetTransform.scale.setValue([100,100,100]);

回転(2D)を設定する

targetLayer.rotation.setValue(128);

Z回転を設定する

targetTransform.zRotation.setValue(128);

不透明度を設定する

targetTransform.opacity.setValue(100);

結構めんどくさいというかややこしいので、自分の使いやすい関数を用意したほうがいいかもー