[AE_scripts] 選択したレイヤに対してのマルチ処理
参考HP:
ex). 選択しているレイヤーそれぞれのひとつ上の階層にヌルレイヤーを追加する
http://aejsx.hiroshisaito.net/home/after-effects-scripting-examples/example2_addnulls
--------------------------------------------------
■ Modify code
1, コンポジションの1行名に複製元の素材を準備
2, 選択レイヤーの下に複製したレイヤーを配置
3, 複製レイヤーを選択レイヤーに親子付
4, 複製レイヤーを3Dレイヤー化
5, 位置、回転値に初期値を代入
--
//変数宣言&初期化
//(コード内に散在させてもいいのですが、個人的には各変数スコープの最初で宣言するようにしています)
//例文ではすべてグローバルスコープになっています。
//現在アクティブになっているコンポジションを取得。何もアクティブでない場合はnullが取得されます。
var activeComp= app.project.activeItem;
var newLayers = new Array();
var selectedLayers= new Array();
var tempLength, i, j;
//まず処理を加える前にactiveItem(アクティブになっているコンポジションの値)がnullでないことを確認します。
//同時にそのアイテムがCompItemであることを確認します。
//2つの条件が揃わない場合は、最後のアラートを表示してスクリプトは終了します。
if(activeComp&&(activeComp instanceof CompItem)){
//アクティブなコンポジションで選択されているレイヤーの数を取得します。
tempLength = activeComp.selectedLayers.length;
//選択されているレイヤーの数が1以上の場合そのレイヤーの上にNullを追加します。
if(tempLength > 0){
//選択されているレイヤーを別の配列に一時的に格納します。
for(i=0; i < tempLength; i++){
selectedLayers[i] = activeComp.selectedLayers[i];
}
//複製したレイヤーを選択レイヤーの下に配置+初期設定
for (j=0; j < tempLength; j++) {
newLayers[j] = activeComp.layer(1).duplicate();
newLayers[j].moveAfter(selectedLayers[j]);
newLayers[j].parent = selectedLayers[j];
newLayers[j].threeDLayer = true;
newLayers[j].position.setValue([0, 0, 0]);
newLayers[j].transform.orientation.setValue([0, 0, 0]);
newLayers[j].transform.xRotation.setValue([0]);
newLayers[j].transform.yRotation.setValue([0]);
newLayers[j].transform.zRotation.setValue([0]);
}
} else {
//レイヤーが選択されていない場合アラートを出すようにしています。
alert('レイヤーが選択されていません');
}
} else {
//アクティブになっているアイテムが存在しない、あるいはアイテムがコンポジションでない場合はアラート表示
alert('現在アクティブになっているコンポジションがありません');
}
参考、
//レイヤーを複製
//app.project.item(index).layer(index).duplicate();
//親子付 /*
for (var i=1; i<=app.project.item(1).layers.length; i++) {
if(i !== 1) {
app.project.item(1).layer(i).parent = app.project.item(1).layer(i-1);
}
}
app.project.item(1).layer(i).parent = app.project.item(1).layer(i-1);
*/
ex). 選択しているレイヤーそれぞれのひとつ上の階層にヌルレイヤーを追加する
http://aejsx.hiroshisaito.net/home/after-effects-scripting-examples/example2_addnulls
--------------------------------------------------
■ Modify code
1, コンポジションの1行名に複製元の素材を準備
2, 選択レイヤーの下に複製したレイヤーを配置
3, 複製レイヤーを選択レイヤーに親子付
4, 複製レイヤーを3Dレイヤー化
5, 位置、回転値に初期値を代入
--
//変数宣言&初期化
//(コード内に散在させてもいいのですが、個人的には各変数スコープの最初で宣言するようにしています)
//例文ではすべてグローバルスコープになっています。
//現在アクティブになっているコンポジションを取得。何もアクティブでない場合はnullが取得されます。
var activeComp= app.project.activeItem;
var newLayers = new Array();
var selectedLayers= new Array();
var tempLength, i, j;
//まず処理を加える前にactiveItem(アクティブになっているコンポジションの値)がnullでないことを確認します。
//同時にそのアイテムがCompItemであることを確認します。
//2つの条件が揃わない場合は、最後のアラートを表示してスクリプトは終了します。
if(activeComp&&(activeComp instanceof CompItem)){
//アクティブなコンポジションで選択されているレイヤーの数を取得します。
tempLength = activeComp.selectedLayers.length;
//選択されているレイヤーの数が1以上の場合そのレイヤーの上にNullを追加します。
if(tempLength > 0){
//選択されているレイヤーを別の配列に一時的に格納します。
for(i=0; i < tempLength; i++){
selectedLayers[i] = activeComp.selectedLayers[i];
}
//複製したレイヤーを選択レイヤーの下に配置+初期設定
for (j=0; j < tempLength; j++) {
newLayers[j] = activeComp.layer(1).duplicate();
newLayers[j].moveAfter(selectedLayers[j]);
newLayers[j].parent = selectedLayers[j];
newLayers[j].threeDLayer = true;
newLayers[j].position.setValue([0, 0, 0]);
newLayers[j].transform.orientation.setValue([0, 0, 0]);
newLayers[j].transform.xRotation.setValue([0]);
newLayers[j].transform.yRotation.setValue([0]);
newLayers[j].transform.zRotation.setValue([0]);
}
} else {
//レイヤーが選択されていない場合アラートを出すようにしています。
alert('レイヤーが選択されていません');
}
} else {
//アクティブになっているアイテムが存在しない、あるいはアイテムがコンポジションでない場合はアラート表示
alert('現在アクティブになっているコンポジションがありません');
}
参考、
//レイヤーを複製
//app.project.item(index).layer(index).duplicate();
//親子付 /*
for (var i=1; i<=app.project.item(1).layers.length; i++) {
if(i !== 1) {
app.project.item(1).layer(i).parent = app.project.item(1).layer(i-1);
}
}
app.project.item(1).layer(i).parent = app.project.item(1).layer(i-1);
*/
0 コメント:
コメントを投稿