2013-07-18 48 views
1

我有一個包含100個圖層的PSD。大多數組都與組內的單個元素(嵌套)分組。Photoshop CS6將嵌套圖層導出爲PNG?

如何導出到PNG某些個別組(其中嵌套層)?

我不想運行將所有圖層導出爲PNG腳本,只需要將各個嵌套組(圖層)導出到PNG。我發現了一些其他的第三方腳本,但它們導出了所有內容。只需要導出我選擇的那些。

在此先感謝

+0

目前,我的工作流程是:選擇組>將文檔複製到新文檔>另存爲PNG – ThePlague

回答

1

此腳本應該做你想做的。它只適用於你想要選擇的羣組(不是該羣組內的圖層),我沒有廣泛測試它,並且我假設你沒有羣組內的羣組(這成爲頭痛)

// export png from group 
srcDoc = app.activeDocument; 
var allLayers = new Array(); 
var selectedLayer = srcDoc.activeLayer; 
var theLayers = collectAllLayers(app.activeDocument, 0); 
var groupName = ""; 

// function collect all layers 
function collectAllLayers (theParent, level) 
{ 
    for (var m = theParent.layers.length - 1; m >= 0; m--) 
    { 
    var theLayer = theParent.layers[m]; 

    // apply the function to layersets; 
    if (theLayer.typename == "LayerSet") 
    { 
     var goCode = false; 
     allLayers.push(level + theLayer.name); 
     groupName = theLayer.name 
     // alert(level + " " + theLayer.name) 
     collectAllLayers(theLayer, level + 1) 


      var subDoc = srcDoc.layers[m]; 
      //alert(subDoc) 
      var numOfSubLayers = subDoc.layers.length; 

      //alert(numOfSubLayers) 
      for (var j = numOfSubLayers -1; j >= 0 ; j--) 
      { 

      if (subDoc.layers[j].typename == "ArtLayer") 
      { 
       // if the selected (active) layer is in the group 
       if (theLayer == selectedLayer) 
       { 
       var mylayerName = subDoc.layers[j].name 
       srcDoc.activeLayer = subDoc.layers[j]; 
       // alert("Selected: " + mylayerName + " in " + groupName) 
       processLayer(mylayerName) 
       //selectAllLayersInGroup(groupName) 
       } 
      } 
      } 
    } 
    } 
} 



function processLayer(alayername) 
{ 
    // duplicate image into new document 
    // ======================================================= 
    var id2784 = charIDToTypeID("Mk "); 
    var desc707 = new ActionDescriptor(); 
    var id2785 = charIDToTypeID("null"); 
    var ref508 = new ActionReference(); 
    var id2786 = charIDToTypeID("Dcmn"); 
    ref508.putClass(id2786); 
    desc707.putReference(id2785, ref508); 
    var id2787 = charIDToTypeID("Nm "); 
    desc707.putString(id2787, alayername); 
    var id2788 = charIDToTypeID("Usng"); 
    var ref509 = new ActionReference(); 
    var id2789 = charIDToTypeID("Lyr "); 
    var id2790 = charIDToTypeID("Ordn"); 
    var id2791 = charIDToTypeID("Trgt"); 
    ref509.putEnumerated(id2789, id2790, id2791); 
    desc707.putReference(id2788, ref509); 
    executeAction(id2784, desc707, DialogModes.NO); 

    // create new layer 
    var layerRef = app.activeDocument.artLayers.add() 
    layerRef.name = "temp" 
    layerRef.blendMode = BlendMode.NORMAL 

    //merge visible 
    // ======================================================= 
    var id1435 = charIDToTypeID("MrgV"); 
    executeAction(id1435, undefined, DialogModes.NO); 

    // Set filePath and fileName to source path 
    filePath = srcDoc.path + '/' + app.activeDocument.name + '.png'; 

    // save out the image 
    var pngFile = new File(filePath); 
    pngSaveOptions = new PNGSaveOptions(); 
    pngSaveOptions.embedColorProfile = true; 
    pngSaveOptions.formatOptions = FormatOptions.STANDARDBASELINE; 
    pngSaveOptions.matte = MatteType.NONE; pngSaveOptions.quality = 1; 

    activeDocument.saveAs(pngFile, pngSaveOptions, false, Extension.LOWERCASE); 

    // alert(filePath) 
    // close that save png 
    app.activeDocument.close() 

    // selects document that's been open the longest 
    app.activeDocument = srcDoc; 
}