Photoshop JS 脚本来创建和应用图层蒙版 [英] Photoshop JS script to create and apply a layer mask

查看:63
本文介绍了Photoshop JS 脚本来创建和应用图层蒙版的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我用 JS 编写了一个 Photoshop 脚本,它获取每个图层文件夹并像精灵表一样将其隔开.我已经弄清楚了那部分,但我试图在运行脚本时消除任何形式的人为错误.现在,您需要使用每个图层文件夹的正确命名来准备文件,并且还必须为选区应用图层蒙版.

I wrote a Photoshop script in JS that takes each layer folder and spaces it out like a sprite sheet. I've figured out that part, but I'm trying to remove any form of human error while running the script. Right now, you need to prep your file with the correct naming of each layer folder, and you also have to apply a layer mask to the selection.

我想消除用户应用图层蒙版的需要.我可以选择图层,然后选择要遮罩的部分,但我不知道如何应用或创建遮罩.

I want to remove the need for the user to apply a layer mask. I can select the layer, and then select the portion I want to mask, but I have no clue on how to apply or create the mask.

我想应用它的地方:

function maskIt(){
    if(currentFrameCount < (frameNumber-1)){
        currentFrameCount = currentFrameCount+1;
        currentFrame = ("frame"+currentFrameCount);
        activeDocument.layers[currentFrame].visable;
        activeDocument.selection.selectAll();
        //createMask();
        maskComplete = false;
    } else  if (currentFrameCount == (frameNumber-1)){
        currentFrameCount = currentFrameCount+1;
        currentFrame = ("frame"+currentFrameCount);
        activeDocument.layers[currentFrame].visable;
        activeDocument.selection.selectAll();
        //createMask();
        currentFrameCount = 0;
        maskComplete = true;
    }
}

推荐答案

这是一个更简洁的版本,添加了 try 以检查掩码是否存在.如果你想应用任何掩码,只需移动 deleteLayerMask(true); 下面的行 catch (e) {}

Here is a cleaner version with try added to check for the existence of a mask. If you want to apply any mask, just move the line deleteLayerMask(true); below catch (e) {}

addMasks();

function addMasks(){

    try{
        loadLayerSelection();
        addLayerMask();
        deleteLayerMask(true);
        } catch (e) {}
};

// =======================================================
function loadLayerSelection() {
    var c2t = function (s) {
        return app.charIDToTypeID(s);
    };

    var s2t = function (s) {
        return app.stringIDToTypeID(s);
    };

    var descriptor = new ActionDescriptor();
    var reference = new ActionReference();
    var reference2 = new ActionReference();

    reference.putProperty( s2t( "channel" ), s2t( "selection" ));
    descriptor.putReference( c2t( "null" ), reference );
    reference2.putEnumerated( s2t( "channel" ), s2t( "channel" ), s2t( "transparencyEnum" ));
    descriptor.putReference( s2t( "to" ), reference2 );
    executeAction( s2t( "set" ), descriptor, DialogModes.NO );
}

// =======================================================
function addLayerMask() {
    var c2t = function (s) {
        return app.charIDToTypeID(s);
    };

    var s2t = function (s) {
        return app.stringIDToTypeID(s);
    };

    var descriptor = new ActionDescriptor();
    var reference = new ActionReference();

    descriptor.putClass( s2t( "new" ), s2t( "channel" ));
    reference.putEnumerated( s2t( "channel" ), s2t( "channel" ), s2t( "mask" ));
    descriptor.putReference( s2t( "at" ), reference );
    descriptor.putEnumerated( s2t( "using" ), c2t( "UsrM" ), s2t( "revealSelection" ));
    executeAction( s2t( "make" ), descriptor, DialogModes.NO );
}

// =======================================================
function deleteLayerMask(apply) {
    var c2t = function (s) {
        return app.charIDToTypeID(s);
    };

    var s2t = function (s) {
        return app.stringIDToTypeID(s);
    };

    var descriptor = new ActionDescriptor();
    var reference = new ActionReference();

    reference.putEnumerated( s2t( "channel" ), s2t( "channel" ), s2t( "mask" ));
    descriptor.putReference( c2t( "null" ), reference );
    descriptor.putBoolean( s2t( "apply" ), apply );
    executeAction( s2t( "delete" ), descriptor, DialogModes.NO );
}

这篇关于Photoshop JS 脚本来创建和应用图层蒙版的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆