7 Replies Latest reply on Mar 26, 2014 3:40 PM by Rananil

    Export Clipped Layers as TIFFs using Layer name as Filename

    craftycurate Level 1

      (Cross-posted from Mac forum - just realised there is a scripting forum!)

       

      Hi All

       

      I'm trying to solve the following problem and I don't think an Action will cut it.

       

      I have a number of PS5 files which contain a number of product swatches clipped onto a base layer which provides the swatch outline and a drop shadow. The name of each layer is the name of the product shown on that layer.

       

      What I want to do is to export a TIFF file for each layer, but it has to be clipped onto the base layer to have the shared appearance, so a simple "Export Layers as separate images" won't do. The steps are

       

      1. Start with all layers visible

      2. Export top layer as TIFF using the layer name as file name.

      3. Hide this layer, and move to next layer down.

      4. Repeat step 2 until the topmost visible layer is a Vector Smart Object (the clipping mask), then quit.

       

      I have never attempted PS Scripting before though I have a fair bit of coding experience.

       

      Is this achievable using a PS Script, and if so, what might a good way to approach it be? I'll keep searching elsewhere for an answer in the meantime, but I reckon someone here will be able to suggest a good strategy for this.

       

      Cheers

      Richard

        • 1. Re: Export Clipped Layers as TIFFs using Layer name as Filename
          JJMack Most Valuable Participant

          Have you looked at the Export Layers To Files.jsx script that ships with Photoshop?

          • 2. Re: Export Clipped Layers as TIFFs using Layer name as Filename
            Michael L Hale Level 5

            Export Layers To Files will not work but if you quickly made layercomps for each product you could use Layer Comps to Files. That is what I would recommend you try first.

             

            But if you want to see a custom script, I have a few questions. Where do you want the tiffs saved? In the same folder? Do you want the tiffs saved as layered files or flattened. I assume flattened. Do you want the tiffs saved with compression?

            • 3. Re: Export Clipped Layers as TIFFs using Layer name as Filename
              craftycurate Level 1

              Thanks ... in reply:

               

              I tried to find the Export Layers to Files script as a basis for my own, but the jsx didn't seem to be in the Sample Scripts folder i looked in. Will hunt around again.

               

              It wouldn't matter if the TIFFs were saved in the same folder, for easier scripting - can always filter them in Bridge.

               

              The TIFFs will be flattened, but with transparency, as the swatches have a drop shadow. not worried about compression really.

               

              Cheers

              Richard

              • 4. Re: Export Clipped Layers as TIFFs using Layer name as Filename
                JJMack Most Valuable Participant

                You will find Photoshop scripts (not samples) in \Program Files\Adobe\Adobe Photoshop CS5\Presets\Scripts\ you will find both scripts on a 32 bit system. On a 64 bit systen they will be in both the 64Bit and 32 bit versions \Presets\Scripts\  you will find Layer Comps To Files.jsx and Export Layers To Files.jsx  there Michael knows these scripts better them me. I just know they exist have never needed to use them...

                • 5. Re: Export Clipped Layers as TIFFs using Layer name as Filename
                  Michael L Hale Level 5

                  Something like this should be close.

                   

                  // this assumes:
                  // the activeDocument has been saved at least once
                  // all layer are at the top level ie no layer sets
                  // that all layers are visible and have unique names
                  // that the script should stop when it reaches a SO layer with vector mask
                  // CS4 or higher
                  var savePath = app.activeDocument.path;
                  var doc = app.activeDocument.duplicate();
                  doc.activeLayer = doc.layers[0];
                  while( doc.activeLayer.kind != LayerKind.SMARTOBJECT && !hasVectorMask() ){
                       var f = new File(savePath+'/'+doc.activeLayer.name+'.tif');
                       SaveAsTIFF( f, false, true, true, true );
                       doc.activeLayer.remove();
                  }
                  doc.close(SaveOptions.DONOTSAVECHANGES);
                  
                  
                  function SaveAsTIFF( inFileName, inLayers, inTransparency, inEmbedICC, inLZW ) {
                       var tiffSaveOptions = new TiffSaveOptions();
                       tiffSaveOptions.embedColorProfile = inEmbedICC;
                       tiffSaveOptions.layers = inLayers;
                       tiffSaveOptions.transparency = inTransparency;
                       if ( inLZW ) {
                            tiffSaveOptions.imageCompression = TIFFEncoding.TIFFLZW;
                       } else {
                            tiffSaveOptions.imageCompression = TIFFEncoding.NONE;
                       } 
                       app.activeDocument.saveAs( File( inFileName ), tiffSaveOptions );
                  };
                  function hasVectorMask(){
                       var ref = new ActionReference();
                       ref.putEnumerated( charIDToTypeID("Lyr "), charIDToTypeID("Ordn"), charIDToTypeID("Trgt") ); 
                       return executeActionGet( ref ).getBoolean( stringIDToTypeID( 'hasVectorMask' ) );
                  };
                  
                  1 person found this helpful
                  • 6. Re: Export Clipped Layers as TIFFs using Layer name as Filename
                    craftycurate Level 1

                    Great thanks - will give it a go!

                     

                    Cheers

                    Richard

                    • 7. Re: Export Clipped Layers as TIFFs using Layer name as Filename
                      Rananil

                      Man, Actually I am designer and create mobile case design. I have done mobile cover design preview in psd. so many layers created. Top layer-group Camera & button.  Second Layer-group different mobile  cover designs in clipping mask.. I want to export the preview (without using Layer comp to files). Means Single design to export without hiding the layers.... 30 design preview in single click....Layer format.jpg