LoginSignup
0
0

More than 5 years have passed since last update.

今スク レイヤーソースの置き換え

Last updated at Posted at 2019-02-04

今日のスクリプトはどんなもの?

今回はレイヤーのソースの置き換えです。(複数可)

どんな時に使う?

今回のケースはコンポジションに大量の写真があり、その写真全て差し替えたいと思ったときに。

使い方

スクリプトを起動させるとボタンが2つあり
まずはプロジェクトパネルから置換する予定のフッテージを選択します。(配列に入る)
そして次に置換したいレイヤーを選択して実行ボタンを押せばソースが置き換えられます。

ちなみに置換する素材はランダムで設定しています。

コード

var winObj = (this instanceof Panel) ? this : new Window('palette', 'フッテージ置き換え', undefined, {resizeable: true});

    var contentsGrp = winObj.add('group',undefined,'contentsGrp');
    contentsGrp.orientation = 'row';
        try{
        var myBannerPath = new File (thisFolderPath+'/youtool_common/Ae_Script_banner.png');
        var banner = contentsGrp.add('image',undefined,myBannerPath);
        banner.alignment = [ScriptUI.Alignment.LEFT,ScriptUI.Alignment.CENTER];
        //~     banner.alignment = [ScriptUI.Alignment.LEFT,ScriptUI.Alignment.CENTER]
        }
        catch(e){
        }

    var button1 = contentsGrp.add("button",undefined,"置換するフッテージを配列にイン");
    var button2 = contentsGrp.add("button",[120,20,200,50],"実行");

winObj.onResizing = winObj.onResize = function () {this.layout.resize();};  

if (winObj instanceof Window) {  
winObj.center();  
winObj.show();  
} else {  
winObj.layout.layout(true);  
winObj.layout.resize();  
} 

button1.onClick = function(){
PushToArray()
}

button2.onClick = function(){
okikae()
}


//グローバル変数
var array = [];


//プロジェクトアイテムを配列に
function PushToArray(){
var selectItems = app.project.selection;
    array = [];
    for (var i = 0; i < selectItems.length; i++) {
        var myItem =  selectItems[i];//選択したオブジェクト
        var myComp = selectItems[i]; // 選択したオブジェクトの名前を取得
            array[i] = myComp;
    }
}

//選択したレイヤー
function okikae(){
var myComp =  app.project.activeItem;
var myLayer = myComp.selectedLayers;
app.beginUndoGroup("アンドゥ");
    for (var i = 0 ; i < myLayer.length ; i ++ ){
        myLayer[i].replaceSource(array[Math.floor( Math.random() * array.length+1 )],false)
    }
app.endUndoGroup();
}
0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0