1 Reply Latest reply on Jul 18, 2013 2:57 PM by Michael L Hale

    Script - create .jpg - using various (visible) layers

    bfsdhjgfsdabhjgbfsd45564 Level 1

      Hello

       

      I have trubble creating a script for Photoshop CS 5.

      I have got a .PSD document with several layers, some of which are visible, some are invisible.

      I want the script to make the selected layer visible (only one layer is selected). Than i want it to create a .jpg including all visible Layers. And I want the .jpg named after the name of the document with the addition of 01 (for example: Document named 123.psd, so create 12301.jpg)

      After that i need the script to make the selected layer invisible. I than want to automatically select the next layer below (or above, doesn't matter), make that one visible and create a .jpg including all visible layers, like before. This .jpg file needs to add the suffix 02 (so create a file 12302.jpg).

      Than make selected layer invisible, select the next layer and repeat.

       

      I found a matching script from 6 years ago on the internet. It works, but painfully slow. I think it is because I am using Photoshop CS 5 and that script was written for a previous version.

       

      Here is the script I am using right now:

       

      var datRef = activeDocument;

      var pfad = Folder.selectDialog("Waehle eine Zielordner");

       

      exportOptionsSaveForWeb = new ExportOptionsSaveForWeb(); 

      exportOptionsSaveForWeb.quality = 60; 

      exportOptionsSaveForWeb.includeProfile = true; 

      exportOptionsSaveForWeb.optimised = true; 

      exportOptionsSaveForWeb.format = SaveDocumentType.JPEG; 

       

      for( var einEbene = 0; einEbene< datRef.artLayers.length; einEbene++) {

       

          for( var ebenTemp = 0; ebenTemp < datRef.artLayers.length; ebenTemp++) {

              if( datRef.artLayers[ebenTemp].name != "Hintergrund"){

                  datRef.artLayers[ebenTemp].visible = false;}

          }

          

          savedState = datRef.activeHistoryState;

          

          if( datRef.artLayers[einEbene].name != "Hintergrund"){

              datRef.artLayers[einEbene].visible = true;

              var saveFile = new File(pfad + "/" + datRef.artLayers[einEbene].name + ".jpg");

              datRef.exportDocument (saveFile, ExportType.SAVEFORWEB, exportOptionsSaveForWeb);}

              

          datRef.activeHistoryState = savedState;

      }

       

      If you can help me, run that script faster, or create a script that does what I described propperly, it'll be mutch appreceated.