8 Replies Latest reply on Mar 20, 2012 11:58 PM by c.pfaffenbichler

    Saving Adj. Layers In a Group

    Danny Noonan

      Hello

      I am trying to create a sctipt that will save all of the adjustement layers in a group to a tiff. The group would always have the same name, somthing like "colors". I am hoping that one adj layer could be turned on, saved as a tif, the adj layer would be turned off and the next adj layer would be turned on, saved as a tif, and turned off then the next and the next etc. We would also need the name of the layer saved in the final tif file name.

       

      If anyone has anything like this or could please help me with this, I would greatly appreciat it.

       

      Thank you.

        • 1. Re: Saving Adj. Layers In a Group
          c.pfaffenbichler Level 9

          I may not follow what you are describing.

          Could you please post s acreenshot or mock up of an exemplary file and the resulting files (both in the application and in Finder)?

          • 2. Re: Saving Adj. Layers In a Group
            Danny Noonan Level 1

            Finder.pngLayers.png

             

             

            Here are some screen shots. The most important things to note is the "colors" group name is static. It will always be in the "Swatch Worker" group. The naming of the adjustment layers will always have the same structure, ex. "Color_CL". We would like any charecter after the "_" in the layer name to be used in the final file name. If this portion of the layer name could be used before the final "_" in the file name, that would be perfect.

             

            I know this is kind of confusing so if you have any more questions please let me know.

             

            Thanks for your help!

            • 3. Re: Saving Adj. Layers In a Group
              c.pfaffenbichler Level 9

              In the original post you omitted to mention that the layer »Swatch« should be visible, it seems.

              Should the resultant tifs be flat or layered?

               

              I think it would be less confusing if you gave more complete details about what you want.

              • 4. Re: Saving Adj. Layers In a Group
                Danny Noonan Level 1

                The tifs should be flat, without any alpha channels and with LZW compression.

                I'm sorry I failed to mention what other layers should be visible. I didn't mention this because we are trusting everthing will be set up the before the script is ran.

                 

                 

                Thanks

                • 5. Re: Saving Adj. Layers In a Group
                  c.pfaffenbichler Level 9

                  You really should describe what you want more exactly right away.

                  Could you give this a try:

                   

                  // thanks to xbytor for regexp;
                  // 2012, use it at your own risk;
                  #target photoshop
                  if (app.documents.length > 0) {
                  var myDoc = app.activeDocument;
                  var docName = myDoc.name;
                  try {var basename = docName.match(/(.*)\.[^\.]+$/)[1];
                  var docPath = myDoc.path}
                  catch (e) {var basename = docName;
                  var docPath = "~/Desktop"};
                  // try to get set »colors« in »swatch worker«;
                  try {
                  var theSet = myDoc.layers.getByName("Swatch Worker").layers.getByName("colors");
                  for (var n = 0; n < theSet.layers.length; n++) {
                  theSet.layers[n].visible = false;
                  };
                  // process;
                  for (var m = 0; m < theSet.layers.length; m++) {
                  var thisLayer = theSet.layers[m];
                  thisLayer.visible = true;
                  var layerName = thisLayer.name;
                  while (layerName.indexOf("/") != -1) {layerName = layerName.replace("/", "_")};
                  saveFlattenedTiff (myDoc, basename + "_" + layerName, docPath)
                  thisLayer.visible = false;
                  }
                  } 
                  catch (e) {alert ("can’t locate folder")};
                  };
                  ////// function to save the flattened tiff from copy //////
                  function saveFlattenedTiff (myDoc, basename, docPath) {
                  tifOpts = new TiffSaveOptions();
                  tifOpts.embedColorProfile = true;
                  tifOpts.imageCompression = TIFFEncoding.TIFFLZW;
                  tifOpts.alphaChannels = false;
                  tifOpts.byteOrder = ByteOrder.MACOS;
                  tifOpts.layers = false;
                  myDoc.saveAs((new File(docPath+"/"+basename+".tif")),tifOpts,true)
                  };
                  
                  • 6. Re: Saving Adj. Layers In a Group
                    Danny Noonan Level 1

                    Hi c.pfaffenbichler,

                    Everytime I try to run the script, it alerts "can't find folder". It looks like you set it up to save to the desktop? ~/Desktop would be my user desktop, correct? I tried putting in the full path but this did not work. Any suggestions would be appreciated.

                     

                    Thank you very much for your help with this so far.

                    • 7. Re: Saving Adj. Layers In a Group
                      Danny Noonan Level 1

                      Okay, I got it to work! I doesn't add the layer name like I hoped it would but I can play around with it.

                       

                      Thanks again for your time!

                      • 8. Re: Saving Adj. Layers In a Group
                        c.pfaffenbichler Level 9

                        It looks like you set it up to save to the desktop?

                        No, desktop is only the alternative in case the file has not been saved yet and therefore lacks a path.

                         

                        I got it to work! I doesn't add the layer name like I hoped it would but I can play around with it.

                        basename + "_" + layerName

                        should include the Layer’s name (as layername is defined as the name of thisLayer).

                        Could you please post a screenshot of the Layers Panel and the resulting files’ names?