1 Reply Latest reply on Aug 15, 2012 4:47 AM by Ghoulfool

    Creating merged output based on multiple layers.

    JessHooks

      I have a file with 4 different layer groups. One layer is a shading layer applied on top of every layer. The other 3 layers contain I'd like to be able to automate/script it so that one layer from each group can get merged into one exported tif file, ideally named by the title of each layer (ie 01Blue-02Green-03yellow.tif).

       

      Right now I select the layers I want to use, then apply a custom action that exports it to tif. I have to rename the file after. Its very laborious, and I make now & again I make a mistake about which layers were selected.

       

      I'm currently running CS4

       

      Thanks!

        • 1. Re: Creating merged output based on multiple layers.
          Ghoulfool Level 1

          Jess,

           

          As my understanding of what you want:

           

          I made a psd with the following layers (from the bottom up) background (white), blue (a layer with something blue on it - layer name "blue"), green (a layer with something green on it - layer name "green") and finally red (a layer with something red on it - layer name, you guessed it "red"). The script will then save out layers, red, blue and green as TIFFS with the layername as the filename

           

          This script will work but it assumes a couple of things:

          1, the top layer is your shading layer,

          2, the background is included.

           

          I wasn't sure if you ment "groups" as in a number of things or layersets (layer groups) so those will get exported but will be blank

           

          // tiff export with shaded layers
          // use at your own risk
          
          // call the source document
          var srcDoc = app.activeDocument;
          var numOfLayers = srcDoc.layers.length;
          
          // main loop starts here
          for (var i = numOfLayers -2; i >= 1  ; i--)
          {
          
              //var tempLayer = srcDoc.activeLayer.name;
              var tempLayer = srcDoc.layers[i]
          
              //switch other the layers off
              switchAllLayersOff(i)
          
                if ((i != numOfLayers -1) && (i != 0))
                  {
                    srcDoc.layers[i].visible = true;
                    decantLayer(tempLayer.name)
                  }
          
          }//end loop
          
          function switchAllLayersOff(idx)
          {
            for (var m = numOfLayers -2; m >= 1  ; m--)
            {
                srcDoc.layers[m].visible = false
            }
             srcDoc.layers[0].visible = true;
             srcDoc.layers[numOfLayers -1].visible = true
             srcDoc.layers[idx].visible = true;
          }
          
          
          function decantLayer(layerName)
          {
          // =======================================================
          var id21 = charIDToTypeID( "Dplc" );
          var desc7 = new ActionDescriptor();
          var id22 = charIDToTypeID( "null" );
          var ref5 = new ActionReference();
          var id23 = charIDToTypeID( "Dcmn" );
          var id24 = charIDToTypeID( "Ordn" );
          var id25 = charIDToTypeID( "Frst" );
          ref5.putEnumerated( id23, id24, id25 );
          desc7.putReference( id22, ref5 );
          var id26 = charIDToTypeID( "Nm  " );
          desc7.putString( id26, layerName );
          executeAction( id21, desc7, DialogModes.NO );
          
          // Set filePath and fileName to source path
          filePath = srcDoc.path + '/' + app.activeDocument.name +'.tiff';
          
          // save out the image
          var tiffFile = new File(filePath);
          tiffSaveOptions = new TiffSaveOptions();
          tiffSaveOptions.byteOrder = ByteOrder.MACOS;
          tiffSaveOptions.layers = false;
          tiffSaveOptions.transparency = true;
          tiffSaveOptions.alphaChannels = true;
          tiffSaveOptions.embedColorProfile = false;
          tiffSaveOptions.imageCompression = TIFFEncoding.TIFFLZW;
          tiffSaveOptions.saveImagePyramid = false; 
          
          activeDocument.saveAs(tiffFile, tiffSaveOptions, false, Extension.LOWERCASE);
          
          //close that document without saving
          app.activeDocument.close(SaveOptions.DONOTSAVECHANGES);
          
          // selects document that's been open the longest
          app.activeDocument = srcDoc;
          }
          

           

          Copy the code above into a text editor, save it out as "myexportscript.jsx" or something, put said script in the Adobe\Adobe Photoshop CS4\Presets\Scripts directory. Next time you run Photoshop you'll find the myexportscrip script on the file>scripts menu.

          Hope it works for you