【问题标题】:photoshop javascript channel contentphotoshop javascript 频道内容
【发布时间】:2017-04-29 21:29:43
【问题描述】:

尝试编写从 RGB 通道中提取遮罩的东西。

我得到了很多带有掩码输出的 .exr 文件作为纯 R G 和 B 层。

我已经这样做了:

    var doc = app.activeDocument;
        function showMasks(docGroups) {    

            //step through the groups
        for (var i=0; i<docGroups.length; i++) {

             try{   
             //step through the layers in each group
            for(layerIndex=0; layerIndex < docGroups[i].artLayers.length; layerIndex++) {
var RGB = [doc.channels.getByName('Red'),doc.channels.getByName('Green'),doc.channels.getByName('Blue')];


                    for(var a in RGB)
                   {

                //create slection from  channel
                doc.selection.load(RGB[a], SelectionType.REPLACE);
                //add new layer
                doc.artLayers.add();
                // REVEAL ALL from selection
                var idMk = charIDToTypeID( "Mk  " );
                var desc62 = new ActionDescriptor();
                var idNw = charIDToTypeID( "Nw  " );
                var idChnl = charIDToTypeID( "Chnl" );
                desc62.putClass( idNw, idChnl );
                var idAt = charIDToTypeID( "At  " );
                var ref20 = new ActionReference();
                var idChnl = charIDToTypeID( "Chnl" );
                var idChnl = charIDToTypeID( "Chnl" );
                var idMsk = charIDToTypeID( "Msk " );
                ref20.putEnumerated( idChnl, idChnl, idMsk );
                desc62.putReference( idAt, ref20 );
                var idUsng = charIDToTypeID( "Usng" );
                var idUsrM = charIDToTypeID( "UsrM" );
                var idRvlS = charIDToTypeID( "RvlS" );
                desc62.putEnumerated( idUsng, idUsrM, idRvlS );
                executeAction( idMk, desc62, DialogModes.NO );


                    }

                 //hide layer, move on to the next
                 docGroups[i].artLayers[layerIndex].visible = false;  

                }

              }   
               catch(e){continue;} 

     }

      }

    showMasks(doc.layerSets);

它工作正常,逐步遍历组和图层,并相应地输出带有图层蒙版的新图层。但是,它仅在图层包含 R G 和 B 时才有效,如果它是只有一种颜色的图层,它会停止。 如果图层不包含所有 3 种通道颜色,我该如何调节它以继续运行? 还是重写一次只做一个频道?

任何想法都非常感谢,谢谢/S

【问题讨论】:

  • 自己解决了这个问题:

标签: javascript rgb photoshop photoshop-script channels


【解决方案1】:

通过检查是否有选择来解决这个问题,即如果没有选择,则通道是空的 -> 继续。

我是一名修图师,目前我收到了很多带有 3d 产品的 .exr:s。 VRay 将 materialID/objectID 输出为 RGB 通道。这极大地加快了工作流程。

像这样使用:将所有 RGB 通道放在一个组中,隐藏所有其他层。调用脚本。

var doc = app.activeDocument;
var a=0;

function hasSelection (doc) {
    var ret = false;
    var as = doc.activeHistoryState;
    doc.selection.deselect();
    if (as != doc.activeHistoryState) {
        ret = true;
        doc.activeHistoryState = as;
    }
    return ret;
}

    function showMasks(docGroups) {    

        //this steps through the groups
        for (var i=0; i<docGroups.length; i++) {

         try{  

            // this steps through the layers in each group
            for(layerIndex=0; layerIndex < docGroups[i].artLayers.length; layerIndex++) {

             //visible layers only    
            if(docGroups[i].artLayers[layerIndex].visible == true){

            //var layer=docGroups[i].artLayers[layerIndex];
           var RGB = [doc.channels.getByName('Red'),doc.channels.getByName('Green'),doc.channels.getByName('Blue')];

                for(a in RGB)
                {
                    //create slection from  channel
                    doc.selection.load(RGB[a], SelectionType.REPLACE);

                    if(hasSelection(activeDocument)){

                    doc.artLayers.add();
                    // REVEAL ALL from selection
                    var idMk = charIDToTypeID( "Mk  " );
                    var desc62 = new ActionDescriptor();
                    var idNw = charIDToTypeID( "Nw  " );
                    var idChnl = charIDToTypeID( "Chnl" );
                    desc62.putClass( idNw, idChnl );
                    var idAt = charIDToTypeID( "At  " );
                    var ref20 = new ActionReference();
                    var idChnl = charIDToTypeID( "Chnl" );
                    var idChnl = charIDToTypeID( "Chnl" );
                    var idMsk = charIDToTypeID( "Msk " );
                    ref20.putEnumerated( idChnl, idChnl, idMsk );
                    desc62.putReference( idAt, ref20 );
                    var idUsng = charIDToTypeID( "Usng" );
                    var idUsrM = charIDToTypeID( "UsrM" );
                    var idRvlS = charIDToTypeID( "RvlS" );
                    desc62.putEnumerated( idUsng, idUsrM, idRvlS );
                    executeAction( idMk, desc62, DialogModes.NO );

                    }
                    else{a++;}

                }
             //hide layer, move on to the next
            docGroups[i].artLayers[layerIndex].visible = false;
          }
      }

          }       
           catch(e){return;} 

    }
 }

showMasks(doc.layerSets);

干杯。 /S

【讨论】:

    猜你喜欢
    • 2022-11-12
    • 2014-12-09
    • 2021-09-16
    • 2012-02-11
    • 2015-08-19
    • 1970-01-01
    • 1970-01-01
    • 2022-08-12
    • 2018-09-03
    相关资源
    最近更新 更多