photoshop javascript频道内容

时间:2016-12-14 14:00:40

标签: javascript rgb photoshop photoshop-script channels

试图写一些从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

1 个答案:

答案 0 :(得分:0)

通过检查是否进行了选择来解决这个问题,即如果没有做出选择,则频道为空 - &gt;继续。

我作为润色剂工作,目前我正在使用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