2 Replies Latest reply on Jun 30, 2015 8:45 AM by mariap14286444

    Help editing a script

    mariap14286444

      Hi,

       

      Very nearly found a solution to this old problem I have. I've found a script that saves groups as PNGs and it's great but I need it to save to JPEGs instead. I also need to have an option to change the name. In the script is fine although I did like the 'export layers to files' pop up box. They are currently named after the group name which I want to keep, just add to. I'm really sorry for my lack of experience when it comes to stuff like this, I know people have suggested ways to do it but I can't understand how to edit the script itself and get it to work.

      Many many thanks in advance!!

       

       

       

       

      #target photoshop

      function main(){

      if(!documents.length) return;

      var doc = activeDocument;

      var oldPath = activeDocument.path;

      for(var a=0;a<doc .layerSets.length;a++){

      activeDocument.activeLayer = activeDocument.layers.getByName(doc.layerSets[a].name);

      dupLayers();

      activeDocument.mergeVisibleLayers();

      activeDocument.trim(TrimType.TRANSPARENT,true,true,true,true);

      var saveFile= File(oldPath +"/"+doc.layerSets[a].name +".png");

      SavePNG(saveFile);

      app.activeDocument.close(SaveOptions.DONOTSAVECHANGES);

          }

      }

      main();

      function dupLayers() {

          var desc143 = new ActionDescriptor();

              var ref73 = new ActionReference();

              ref73.putClass( charIDToTypeID('Dcmn') );

          desc143.putReference( charIDToTypeID('null'), ref73 );

          desc143.putString( charIDToTypeID('Nm  '), activeDocument.activeLayer.name );

              var ref74 = new ActionReference();

              ref74.putEnumerated( charIDToTypeID('Lyr '), charIDToTypeID('Ordn'), charIDToTypeID('Trgt') );

          desc143.putReference( charIDToTypeID('Usng'), ref74 );

          executeAction( charIDToTypeID('Mk  '), desc143, DialogModes.NO );

      };

      function SavePNG(saveFile){

      var pngOpts = new ExportOptionsSaveForWeb;

      pngOpts.format = SaveDocumentType.PNG

      pngOpts.PNG8 = false;

      pngOpts.transparency = true;

      pngOpts.interlaced = false;

      pngOpts.quality = 100;

      activeDocument.exportDocument(new File(saveFile),ExportType.SAVEFORWEB,pngOpts);

      }

        • 1. Re: Help editing a script
          Pedro Cortez Marques Level 3

          Hope it helps

           

          #target photoshop
          function main(){
              if(!documents.length) return;
              var doc = activeDocument;
              var oldPath = activeDocument.path;
              for(var a=0;a<doc.layerSets.length;a++){
                  activeDocument.activeLayer = activeDocument.layers.getByName(doc.layerSets[a].name);
                  dupLayers();
                  activeDocument.mergeVisibleLayers();
                  activeDocument.trim(TrimType.TRANSPARENT,true,true,true,true);
                  var named = prompt(doc.layerSets[a].name, doc.layerSets[a].name,"New Name is..."); // prompt ( oldName, newName, Title)
                  var saveFile= File(oldPath +"/"+named +".jpg");
                  saveJPG(saveFile,10);
                  app.activeDocument.close(SaveOptions.DONOTSAVECHANGES);
              }
          }
          main();
          
          
          function dupLayers() {
              var desc143 = new ActionDescriptor();
              var ref73 = new ActionReference();
              ref73.putClass( charIDToTypeID('Dcmn') );
              desc143.putReference( charIDToTypeID('null'), ref73 );
              desc143.putString( charIDToTypeID('Nm  '), activeDocument.activeLayer.name );
              var ref74 = new ActionReference();
              ref74.putEnumerated( charIDToTypeID('Lyr '), charIDToTypeID('Ordn'), charIDToTypeID('Trgt') );
              desc143.putReference( charIDToTypeID('Usng'), ref74 );
              executeAction( charIDToTypeID('Mk  '), desc143, DialogModes.NO );
          }
          
          
          function saveJPG(saveFile, jpegQuality) {
              app.activeDocument.flatten(); 
              jpgSaveOptions = new JPEGSaveOptions();
              jpgSaveOptions.embedColorProfile = true;
              jpgSaveOptions.formatOptions = FormatOptions.STANDARDBASELINE;
              jpgSaveOptions.matte = MatteType.NONE;
              jpgSaveOptions.quality = jpegQuality; //1-12
              activeDocument.saveAs(saveFile, jpgSaveOptions, true,Extension.LOWERCASE);
          }
          
          • 2. Re: Help editing a script
            mariap14286444 Level 1

            Absolutely perfect, thanks so much. I very much appreciate it. The pop up box works excellently, just as I wanted. Thanks again!!