UI版本

/*-------------------------------------
Select Parents N Children

Version History
1.0.0  -  Aug 16, 2021
    Initial release
-------------------------------------*/

//______Files Path______
var thisFile = new File(this);
var thisFolderPath = thisFile.path; 
//______Build Main Panel______
function buildUI(thisObj){
    if (thisObj instanceof Panel){
        var win = thisObj;
    }else{
        execute();
    }       
    return win;
}

try{
    var win = buildUI(this);
    var buttonRect = [0, 0, 170, 24];
    var panelButtonSpace = [5, 5, 5, 5];
    var buttonSpace = [0, 30, 0, 30];
    var buttonA = win.add("button", panelButtonSpace + buttonRect, "Trimmed Adjustment Layer");

    buttonA.helpTip = "Shift Click = Add adjustment layers to each selected layers";
    buttonA.onClick = function(){
        execute();
    }
}catch (e){
}
//try catch <-- To make it work even if you don't have it in ScriptUI Panels.

var comp = app.project.activeItem;

// Sort array
function sortArr(arr){
    arr.sort(function(a,b){
        if( a < b ) return -1;
        if( a > b ) return 1;
        return 0;
    });
}

// Add Trimmed Adjustment Layer
function atal(){
    app.beginUndoGroup("atal");
    var comp = app.project.activeItem;
    var slLayers = comp.selectedLayers;
    var inPArr = [];
    var outPArr = [];
    for(i=0; i<slLayers.length; i++){
        inP = slLayers[i].inPoint;
        inPArr.push(inP);
        outP = slLayers[i].outPoint;
        outPArr.push(outP);
    }
    sortArr(inPArr);
    sortArr(outPArr);
    app.executeCommand(2279);   //Adjustment Layer
    var slAdLayers = comp.selectedLayers;
    slAdLayers[0].inPoint = inPArr[0];
    slAdLayers[0].outPoint = outPArr[outPArr.length-1];
    app.endUndoGroup();
}

// Add trimmed adjustment layer to each selected layers
function atalEach(){
    app.beginUndoGroup("atalEach");
    var comp = app.project.activeItem;
    var slLayers = comp.selectedLayers;
    for(i=0; i<slLayers.length; i++){
        inP = slLayers[i].inPoint;
        outP = slLayers[i].outPoint;
        app.executeCommand(2279);   //Adjustment Layer
        var slAdLayers = comp.selectedLayers;
        slAdLayers[0].inPoint = inP;
        slAdLayers[0].outPoint = outP;
        slAdLayers[0].moveBefore(slLayers[i]);
    }
    app.endUndoGroup();
}

// Execute this script
function execute(){
    var keyboardState = ScriptUI.environment.keyboardState;
	if (keyboardState.shiftKey) {
		atalEach();
    }else{
        atal();
    }
}

无UI版本

/*-------------------------------------
Select Parents N Children

Version History
1.0.0  -  Aug 16, 2021
    Initial release
-------------------------------------*/

//______Files Path______
var thisFile = new File(this);
var thisFolderPath = thisFile.path; 
//______Build Main Panel______
function buildUI(thisObj){
    if (thisObj instanceof Panel){
        var win = thisObj;
    }else{
        execute();
    }       
    return win;
}

try{
    var win = buildUI(this);
    var buttonRect = [0, 0, 170, 24];
    var panelButtonSpace = [5, 5, 5, 5];
    var buttonSpace = [0, 30, 0, 30];
    var buttonA = win.add("button", panelButtonSpace + buttonRect, "Trimmed Adjustment Layer");
    buttonA.onClick = function(){
        execute();
    }
}catch (e){
}
//try catch <-- To make it work even if you don't have it in ScriptUI Panels.

var comp = app.project.activeItem;

// Sort array
function sortArr(arr){
    arr.sort(function(a,b){
        if( a < b ) return -1;
        if( a > b ) return 1;
        return 0;
    });
}

// Add Trimmed Adjustment Layer
function atal(){
    app.beginUndoGroup("atal");
    var comp = app.project.activeItem;
    var slLayers = comp.selectedLayers;
    var inPArr = [];
    var outPArr = [];
    for(i=0; i<slLayers.length; i++){
        inP = slLayers[i].inPoint;
        inPArr.push(inP);
        outP = slLayers[i].outPoint;
        outPArr.push(outP);
    }
    sortArr(inPArr);
    sortArr(outPArr);
    app.executeCommand(2279);   //Adjustment Layer
    var slAdLayers = comp.selectedLayers;
    slAdLayers[0].inPoint = inPArr[0];
    slAdLayers[0].outPoint = outPArr[outPArr.length-1];
    app.endUndoGroup();
}

// Add trimmed adjustment layer to each selected layers
function atalEach(){
    app.beginUndoGroup("atalEach");
    var comp = app.project.activeItem;
    var slLayers = comp.selectedLayers;
    for(i=0; i<slLayers.length; i++){
        inP = slLayers[i].inPoint;
        outP = slLayers[i].outPoint;
        app.executeCommand(2279);   //Adjustment Layer
        var slAdLayers = comp.selectedLayers;
        slAdLayers[0].inPoint = inP;
        slAdLayers[0].outPoint = outP;
        slAdLayers[0].moveBefore(slLayers[i]);
    }
    app.endUndoGroup();
}

// Execute this script
function execute(){
    /*
    var keyboardState = ScriptUI.environment.keyboardState;
	if (keyboardState.shiftKey) {
		atalEach();
    }else{
        atal();
    }
    */
   atal();
}

 

您的电子邮箱地址不会被公开。 必填项已用*标注

请下载到本地观看!因为pdf是用的阿里云盘预览,可能部分字体加载不了。

请安装油猴脚本,并下载月离的万事屋脚本。详情请查看菜单 导航 - 用户指引

请在右上角三个点 - 下载管理 - 找到刚才的文件,选择允许下载。 或者换个浏览器