2016-12-14 2 views
0

en essayant d'écrire quelque chose qui extrait les masques des canaux RVB.photoshop javascript contenu du canal

Je reçois beaucoup de fichiers .exr avec des masques de sortie sous forme de couches R G et B pures.

je l'ai fait:

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); 

qui fonctionne bien, étapes par des groupes et des couches et des sorties de nouvelles couches avec couche-masques en conséquence. cependant, cela ne fonctionne que si une couche contient R G et B, s'il s'agit d'une couche avec une seule couleur, elle s'arrête. comment puis-je le conditionner pour continuer à fonctionner si une couche ne contient pas toutes les 3 couleurs de canal? ou réécriture pour faire un canal à la fois?

des idées très apprécié, merci/S

+0

résolu moi-même: – SEJM

Répondre

0

moi-même résolu en vérifiant s'il y a une sélection effectuée, à savoir s'il n'y a pas de sélection fait, le canal est vide -> passer.

Je travaille comme retoucheur et actuellement je reçois beaucoup de .exr: s avec 3d-products. VRay génère materialID/objectID en tant que passes RGB. cela accélère considérablement le flux de travail.

utiliser comme ceci: mettre tous les passages RGB dans un groupe, masquer tous les autres calques. appel script.

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); 

acclamations./S