1

我有一个包含 100 层的 PSD。大多数都与组内的单个元素分组(嵌套)。

如何将某些单独的组导出到 PNG(其中包含嵌套层)?

我不想运行将所有图层导出到 PNG 脚本,只需将单个嵌套组(图层)导出到 PNG。我发现了其他一些 3rd 方脚本,但它们导出了所有内容。只需要导出我选择的那些。

提前致谢

4

1 回答 1

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;
}
于 2013-07-18T09:13:13.633 回答