17 Replies Latest reply on Sep 19, 2016 6:37 PM by Chuck Uebele

    changes to this script

    Vfxvenkat98 Level 1

      hi,

           How to add save layersets along with Background layer command to this script

       

       

      1. #target photoshop 
      2. function main(){ 
      3. if(!documents.length) return; 
      4. var doc = activeDocument; 
      5. var oldPath = activeDocument.path; 
      6. for(var a=0;a<doc.layerSets.length;a++){ 
      7. activeDocument.activeLayer = activeDocument.layers.getByName(doc.layerSets[a].name); 
      8. dupLayers(); 
      9. activeDocument.mergeVisibleLayers(); 
      10. activeDocument.trim(TrimType.TRANSPARENT,true,true,true,true); 
      11. var saveFile= File(oldPath +"/"+doc.layerSets[a].name +".psd"); 
      12. SavePSD(saveFile); 
      13. app.activeDocument.close(SaveOptions.DONOTSAVECHANGES); 
      14.     } 
      15. main(); 
      16. function dupLayers() {  
      17.     var desc143 = new ActionDescriptor(); 
      18.         var ref73 = new ActionReference(); 
      19.         ref73.putClass( charIDToTypeID('Dcmn') ); 
      20.     desc143.putReference( charIDToTypeID('null'), ref73 ); 
      21.     desc143.putString( charIDToTypeID('Nm  '), activeDocument.activeLayer.name ); 
      22.         var ref74 = new ActionReference(); 
      23.         ref74.putEnumerated( charIDToTypeID('Lyr '), charIDToTypeID('Ordn'), charIDToTypeID('Trgt') ); 
      24.     desc143.putReference( charIDToTypeID('Usng'), ref74 ); 
      25.     executeAction( charIDToTypeID('Mk  '), desc143, DialogModes.NO ); 
      26. }; 
      27. function SavePSD(saveFile){  
      28. psdSaveOptions = new PhotoshopSaveOptions();  
      29. psdSaveOptions.embedColorProfile = true;  
      30. psdSaveOptions.alphaChannels = true;   
      31. activeDocument.saveAs(saveFile, psdSaveOptions, true, Extension.LOWERCASE);  
        • 1. Re: changes to this script
          JJMack Most Valuable Participant

          Have you tried removing the merge visible layers.

          • 2. Re: changes to this script
            Vfxvenkat98 Level 1

            Yeah I tried that commenting out link but not working it just duplicates only layersets

            • 3. Re: changes to this script
              JJMack Most Valuable Participant

              What are you trying to do? Why ae you using that  script in the first place.  Have you looked a the Image processor,  Image processor pro plugin  and the Picture processor scripts?

              • 4. Re: changes to this script
                Vfxvenkat98 Level 1

                I want all my layergroups are duplicated one by one in separate tiff documents.

                So that I am using the above one it does it job right now by duplicate the layerset to new document with the layer group name but the problem is is doesn't save those with background.

                I had used image processor it doesn't worked for me

                • 5. Re: changes to this script
                  Chuck Uebele Adobe Community Professional & MVP

                  So your final result, you want a flattened tiff file with each one of your layer sets plus the background layer, correct? If that's the case, I would approach this script (use scriptlistener to record many of the steps) would be to:

                  1. Have master file open

                  2. record number of layersets (groups) for a loop.

                  3. turn off visibility of all layersets.

                  4. create loop to turn on each layer set in order, have the BG layer visible

                  5. create a copy of the entire file and use the option to merge visible.

                  6. Save the copy file and close.

                  7. Loop continues and turns off visibility of layer set that was just saved and turns on next one. Loop continues.

                  • 6. Re: changes to this script
                    Vfxvenkat98 Level 1

                    Merging visible layer i dont want that i want a duplicated layer group and its background from master file.

                    • 7. Re: changes to this script
                      Vfxvenkat98 Level 1
                      1. #target photoshop
                      2. function main(){
                      3. if(!documents.length) return;
                      4. var doc = activeDocument;
                      5. var oldPath = activeDocument.path;
                      6. for(var a=0;a<doc.layerSets.length;a++){
                      7. activeDocument.activeLayer = activeDocument.layers.getByName(doc.layerSets[a].name);
                      8. dupLayers();
                      9. activeDocument.trim(TrimType.TRANSPARENT,true,true,true,true);
                      10. var saveFile= File(oldPath +"/"+doc.layerSets[a].name +".psd");
                      11. SavePSD(saveFile);
                      12. app.activeDocument.close(SaveOptions.DONOTSAVECHANGES);
                      13.     }
                      14. }
                      15. main();
                      16. function dupLayers() { 
                      17.     var desc143 = new ActionDescriptor();
                      18.         var ref73 = new ActionReference();
                      19.         ref73.putClass( charIDToTypeID('Dcmn') );
                      20.     desc143.putReference( charIDToTypeID('null'), ref73 );
                      21.     desc143.putString( charIDToTypeID('Nm  '), activeDocument.activeLayer.name );
                      22.         var ref74 = new ActionReference();
                      23.         ref74.putEnumerated( charIDToTypeID('Lyr '), charIDToTypeID('Ordn'), charIDToTypeID('Trgt') );
                      24.     desc143.putReference( charIDToTypeID('Usng'), ref74 );
                      25.     executeAction( charIDToTypeID('Mk  '), desc143, DialogModes.NO );
                      26. };
                      27. function SavePSD(saveFile){ 
                      28. psdSaveOptions = new PhotoshopSaveOptions(); 
                      29. psdSaveOptions.embedColorProfile = true; 
                      30. psdSaveOptions.alphaChannels = true;  
                      31. activeDocument.saveAs(saveFile, psdSaveOptions, true, Extension.LOWERCASE); 
                      32. }
                      • 8. Re: changes to this script
                        Vfxvenkat98 Level 1

                        how these many steps can be created using script listener is it possible to create a loop in script listener plugin

                        • 9. Re: changes to this script
                          Vfxvenkat98 Level 1

                          I mean i use script listener only for doing some functions like photoshop action does

                          • 10. Re: changes to this script
                            Chuck Uebele Adobe Community Professional & MVP

                            Okay, if you want to keep the layers intact, you can do it two different ways:

                            1. Make a copy of the file but don't use merge visible. Then loop though that copy file and delete all the other layersets and save.

                             

                            2. Use the copy layers command from the main menu to record copying and moving a layer set to a new file of the same dimension. Copy the background layer also, then save and close.

                            • 11. Re: changes to this script
                              Vfxvenkat98 Level 1

                              the above script selects the layer groups one by one from top order but its does not select the background while duplicating

                               

                              thats the main problem please help me on that part

                              • 12. Re: changes to this script
                                JJMack Most Valuable Participant

                                You would need to  re-program the main function. For each group It would create a new document with a canvas the size of the background layer  Using duplicate Background Layer into a new document with the name of the Current Document Name + Group Name. Then duplicate the layers within the current group into that document "Current Document Name + Group Name". If you want to preserve layers you would not want to merge visible. You would need to Save and close "Current Document Name + Group Name" As your layered or flattened Tiff.

                                 

                                The new document containing the Background would be created after statement 6 before statement 7  the dupLayers function would need to the dupe the layers into the document "Current Document Name + Group Name" so that action manager code would need to be changed and have the "Current Document Name + Group Name"  be a parameter.  You need to change the save as PSD to save as Tiff.

                                 

                                If the bottom layer is actually a Background layer that layer does not support transparency so the Trim transparency statement is not needed. So you can delete 9 and 10.  Statement 11 need a little update.

                                • 13. Re: changes to this script
                                  Vfxvenkat98 Level 1

                                  Thanks Mack

                                   

                                  Can you tell me some example on that part i am confused what function need to set there

                                  • 14. Re: changes to this script
                                    Chuck Uebele Adobe Community Professional & MVP

                                    Try this:

                                     

                                    #target photoshop
                                        function main(){
                                        if(!documents.length) return;
                                        var doc = activeDocument;
                                        var oldPath = activeDocument.path;
                                        var newName
                                        for(var a=0;a<doc.layerSets.length;a++){
                                        activeDocument.activeLayer = activeDocument.layers.getByName(doc.layerSets[a].name);    
                                        dupLayers();
                                        var docCopy = activeDocument;
                                        activeDocument = doc
                                        doc.activeLayer = doc.layers[doc.layers.length-1]
                                        doc.activeLayer.duplicate(docCopy,ElementPlacement.PLACEATEND);
                                        activeDocument = docCopy
                                        activeDocument.trim(TrimType.TRANSPARENT,true,true,true,true);
                                        var saveFile= File(oldPath +"/"+doc.layerSets[a].name +".psd");
                                        SavePSD(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 SavePSD(saveFile){ 
                                        psdSaveOptions = new PhotoshopSaveOptions(); 
                                        psdSaveOptions.embedColorProfile = true; 
                                        psdSaveOptions.alphaChannels = true;  
                                        activeDocument.saveAs(saveFile, psdSaveOptions, true, Extension.LOWERCASE); 
                                        } 
                                    
                                    • 15. Re: changes to this script
                                      JJMack Most Valuable Participant

                                      You need two duplicate layers on duplicates the background into a new document the other duplicates the layer within a group to a document.  It needs the be the same document.  and doing the dupe will switch to the new document,  So after duping the background you nee to switch back to the previous current  document document so you can duplicate the groups layers.  The current script has one dupe layers and does not name the document.  The two dupe you need need to name the same document. So the action manager functions need to have a parameter to name the target document. The for loop in the current script processes each group one at a time.

                                      Capture.jpg

                                      • 16. Re: changes to this script
                                        JJMack Most Valuable Participant

                                        Works for me but I would have the original doc name also in the new file names.  Perhaps also the value of a for there can be be groups with identical names anf I would do some texsting with nested groups to see how they get done.

                                         

                                        Groups within groups remain that way only top level groups have new layered files created. So if want them to be seperate  you would need to make this a recursive process somehow.

                                        • 17. Re: changes to this script
                                          Chuck Uebele Adobe Community Professional & MVP

                                          Yea, that would be a good idea.