4 Replies Latest reply: Jan 11, 2010 8:36 PM by k.loy RSS

    Save Selected Layers (started in general photoshop forum)

    k.loy Community Member

      So this is a continuation of the thread started in the general photoshop forum about exporting layers.

       

      Thanks! Those were helpful tips.  I have another question that may not be as easy...

       

      I have a top layer that I want to serve as a border for all the other layers.  Is there a way to automate that? So that it save every layer individually with the top layer?

       

      Thanks

        • 1. Re: Save Selected Layers (started in general photoshop forum)
          Michael L Hale Community Member

          Are any of your layers in layersets? What you want can be scripted but it will run faster if it doesn't have to deal with layerset.

          • 3. Re: Save Selected Layers (started in general photoshop forum)
            Michael L Hale Community Member

            Well this might need some fine tuning but it will save each layer with the top(border) layer as a jpg in the same folder as the document using the layer's name as the filename.

             

            // refence to selected document
            var doc = app.activeDocument;
            // path to doc
            var saveFolder = doc.path;
            // referece to top layer
            var borderLayer = doc.layers[0];
            // make top layer the active layer
            doc.activeLayer = borderLayer;
            // hide all the other layers
            hideOtherLayers();
            // loop remaining layer and save each with border
            for( var i = 1; i < doc.layers.length; i++ ){
               // reference the layer
               var current = doc.layers[i];
               // turn on the layer
               current.visible = true;
               // save the layer with border
               saveAsJPG( new File( saveFolder+'/'+current.name+'.jpg'), 8 );
               // turn off layer
               current.visible = false; 
               // next layer
            } 
            
            function hideOtherLayers(){//activeLayer
                var desc = new ActionDescriptor();
                        var ref = new ActionReference();
                        var list = new ActionList();
                        ref.putEnumerated( charIDToTypeID( "Lyr " ), charIDToTypeID( "Ordn" ), charIDToTypeID( "Trgt" ) );
                    list.putReference( ref );
                desc.putList( charIDToTypeID( "null" ), list );
                desc.putBoolean( charIDToTypeID( "TglO" ), true );
                 executeAction( charIDToTypeID( "Shw " ), desc, DialogModes.NO );
            }
            function saveAsJPG( saveFile, jpegQuality ){
                 jpgSaveOptions = new JPEGSaveOptions();
                 jpgSaveOptions.embedColorProfile = true;
                 jpgSaveOptions.formatOptions = FormatOptions.STANDARDBASELINE;
                 jpgSaveOptions.matte = MatteType.NONE;
                 jpgSaveOptions.quality = jpegQuality; 
                 activeDocument.saveAs( saveFile, jpgSaveOptions, true,Extension.LOWERCASE );
            }
            
            • 4. Re: Save Selected Layers (started in general photoshop forum)
              k.loy Community Member

              wow!! thanks! i'll give it a whirl right away!