38 Replies Latest reply on Aug 2, 2017 6:02 AM by c.pfaffenbichler

    How to Export JPG files Scripting Automatically

    saranr37921948 Level 1

      I am having art and garment Group folder  separately , i want export the files form Red color garment with red Art, and blue color garment to blue color Art ,etc

       

      Screen Shot 2017-07-20 at 7.33.44 PM.png

       

      Example:

      Screen Shot 2017-07-20 at 7.58.46 PM.png

        • 1. Re: How to Export JPG files Scripting Automatically
          JJMack Most Valuable Participant

          You would set the visible on of what you want visible and everything else visibility off and use Save As naming the file using some file naming convention. You may also be able to use layer comps and export layer comps.  I have never user then but I think they allow you to have different views of your documents

          • 2. Re: How to Export JPG files Scripting Automatically
            saranr37921948 Level 1

            Thanks Mack

             

            I am doing the same now . But tis need to be done automatic thru script is that possible .

             

            Thanks in advance

            • 3. Re: How to Export JPG files Scripting Automatically
              JJMack Most Valuable Participant

              Looking at the structure of your document.  to me it looks like you could script it. Turn all layers visibility off. Then loop through the garment group. Turn on a layer and loop through the color group for that color garment turn on a layer save out a file turn off the layer. when the color group has been processed. the garment loop turn off the current garment layer and moves onto the next garment.

              Basically the script would be two loops. Garment loop and color group loop. Though I have processed all layer in a document with a recursive function  I have never process group of layer by group name.  So I would not know how one address a group by name. I would need to learn how to do that. 

              1 person found this helpful
              • 4. Re: How to Export JPG files Scripting Automatically
                saranr37921948 Level 1

                thanks again JJ

                 

                this is for the PSD file link  https://we.tl/rPQhQSXmmX

                 

                this level of scripting I don't know

                 

                that's why I asked if Help

                 

                any possible other kind of way

                 

                Please help. Sorry for my bad english.

                 

                I appreciate your help!

                 

                • 5. Re: How to Export JPG files Scripting Automatically
                  JJMack Most Valuable Participant

                  I understand you lack scripting knowledge.  So do I. I also have no interest in trying to script it for you. That is for you to do. Scripting is work I'm retired I do not need work.

                  • 6. Re: How to Export JPG files Scripting Automatically
                    saranr37921948 Level 1

                    thank you for your help Sir

                     

                    please suggest anybody

                    • 7. Re: How to Export JPG files Scripting Automatically
                      JJMack Most Valuable Participant

                      I sugested you may want to look into using layer comps.   I have not use them but the may make the job easier.

                       

                      1 person found this helpful
                      • 8. Re: How to Export JPG files Scripting Automatically
                        saranr37921948 Level 1

                        not possible automation script?

                        • 9. Re: How to Export JPG files Scripting Automatically
                          JJMack Most Valuable Participant

                          You do not have the scripting knowledge and do not seem to want to try to develop a script.  I wrote from what I see I believe it could be automated using Photoshop scripting.

                           

                          If you want a custom script you need to write it or have someone program it for you.

                           

                          Personally I have no desire to program the process you want.  Scripting Photoshop is hard for me. I only do it when the process would be simple or  I have need for some process that requires the use of scripting using an action would be my first choice however Actions can not use logic. If I feel other users would find a script I write useful I make it available on the web.  Your process would require logic For if you did it manually and recorded your steps in an action. That action may only work on the document you recorded the action on. Turning on a layers viability in and action requires selecting layers by name  relatively addressing layers in actions only select visible layers. If the action works on the document used to record it. It may work on other document that have exactly the same structure same group names and  the same layer names you do not have duplicate group and layer names. If the document had more layers the would not be processes if a layer the action used was missing the action would fail.

                          • 10. Re: How to Export JPG files Scripting Automatically
                            saranr37921948 Level 1

                            yes I will try action failed

                            • 12. Re: How to Export JPG files Scripting Automatically
                              c.pfaffenbichler Level 9

                              // if group of same name as layer exists save jpg of combinations of layer with each layer in group except if the layer is situated in the group;

                              // 2017, use it at your own risk;

                              #target photoshop

                              if (app.documents.length > 0) {

                              // jpg options;

                              var jpegOptions = new JPEGSaveOptions();

                              jpegOptions.quality = 9;

                              jpegOptions.embedColorProfile = true;

                              jpegOptions.matte = MatteType.NONE;

                              var myDocument = activeDocument;

                              var theName= myDocument.name.match(/(.*)\.[^\.]+$/)[1];

                              var thePath = myDocument.path;

                              // get layers and groupd;

                              var theArrays = getLayerAndGroupsNamesAndIDs();

                              var theLayers = theArrays[0];

                              var theGroups = theArrays[1];

                              // compare layer names to group names;

                              for (var m = 0; m < theLayers.length; m++) {

                              var thisName = theLayers[m][0];

                              selectLayerByID(theLayers[m][1],false);

                              var thisLayer = myDocument.activeLayer;

                              thisLayer.visible = false;

                              hideOthers ();

                              thisLayer.visible = true;

                              for (var n = 0; n < theGroups.length; n++) {

                              // if group has same name as layer;

                              if (thisName == theGroups[n][0]) {

                                selectLayerByID(theGroups[n][1],false);

                                var thisGroup = myDocument.activeLayer;

                                thisGroup.visible = true;

                              // hide all layers in group:

                                for (var p = 0; p < thisGroup.layers.length; p++) {thisGroup.layers[p].visible = false};

                              // save one copy per layer in group;

                                for (var o = 0; o < thisGroup.layers.length; o++) {

                                thisGroup.layers[o].visible = true;

                                myDocument.saveAs((new File(thePath+"/"+theName+"_"+theGroups[n][0]+"_"+String(o)+".jpg")),jpegOptions,true);

                                thisGroup.layers[o].visible = false;

                                }

                                thisGroup.visible = false;

                                }

                              }

                              };

                              myDocument.activeLayer = thisLayer;

                              thisLayer.visible = false;

                              };

                              ////////////////////////////////////

                              function getLayerAndGroupsNamesAndIDs () {

                              // the file;

                              var myDocument = app.activeDocument;

                              // get number of layers;

                              var ref = new ActionReference();

                              ref.putEnumerated( charIDToTypeID("Dcmn"), charIDToTypeID("Ordn"), charIDToTypeID("Trgt") );

                              var applicationDesc = executeActionGet(ref);

                              var theNumber = applicationDesc.getInteger(stringIDToTypeID("numberOfLayers"));

                              // process the layers;

                              var theLayers = new Array;

                              var theGroups = new Array;

                              for (var m = 0; m <= theNumber; m++) {

                              try {

                              var ref = new ActionReference();

                              ref.putIndex( charIDToTypeID( "Lyr " ), m);

                              var layerDesc = executeActionGet(ref);

                              var layerSet = typeIDToStringID(layerDesc.getEnumerationValue(stringIDToTypeID("layerSection")));

                              var isBackground = layerDesc.getBoolean(stringIDToTypeID("background"));

                              // if not layer group collect values;

                              if (layerSet != "layerSectionEnd" && layerSet != "layerSectionStart" && isBackground != true) {

                              var theName = layerDesc.getString(stringIDToTypeID('name'));

                              var theID = layerDesc.getInteger(stringIDToTypeID('layerID'));

                              theLayers.push([theName, theID])

                              };

                              // if  layer group start;

                              if (layerSet == "layerSectionStart") {

                              var theName = layerDesc.getString(stringIDToTypeID('name'));

                              var theID = layerDesc.getInteger(stringIDToTypeID('layerID'));

                              theGroups.push([theName, theID])

                              };

                              }

                              catch (e) {};

                              };

                              /*alert (theLayers.join("\n"));

                              alert (theGroups.join("\n"));*/

                              return [theLayers, theGroups]

                              };

                              // based on code by mike hale, via paul riggott;

                              function selectLayerByID(id,add){

                              add = undefined ? add = false:add

                              var ref = new ActionReference();

                                  ref.putIdentifier(charIDToTypeID("Lyr "), id);

                                  var desc = new ActionDescriptor();

                                  desc.putReference(charIDToTypeID("null"), ref );

                                     if(add) desc.putEnumerated( stringIDToTypeID( "selectionModifier" ), stringIDToTypeID( "selectionModifierType" ), stringIDToTypeID( "addToSelection" ) );

                                    desc.putBoolean( charIDToTypeID( "MkVs" ), false );

                                 try{

                                  executeAction(charIDToTypeID("slct"), desc, DialogModes.NO );

                              }catch(e){

                              alert(e.message);

                              }

                              };

                              ////// hide others //////

                              function hideOthers () {

                              var idShw = charIDToTypeID( "Shw " );

                                  var desc2 = new ActionDescriptor();

                                      var list1 = new ActionList();

                                          var ref1 = new ActionReference();

                                          ref1.putEnumerated( charIDToTypeID( "Lyr " ), charIDToTypeID( "Ordn" ), charIDToTypeID( "Trgt" ) );

                                      list1.putReference( ref1 );

                                  desc2.putList( charIDToTypeID( "null" ), list1 );

                                  desc2.putBoolean( charIDToTypeID( "TglO" ), true );

                              executeAction( idShw, desc2, DialogModes.NO );

                              };

                              1 person found this helpful
                              • 13. Re: How to Export JPG files Scripting Automatically
                                saranr37921948 Level 1

                                thank you very much c.pfaffenbichler

                                 

                                result came this kind of

                                Screen Shot 2017-07-21 at 6.56.05 PM.png

                                 

                                output file this kind of come it's not show Art

                                 

                                Screen Shot 2017-07-21 at 6.57.54 PM.png

                                • 16. Re: How to Export JPG files Scripting Automatically
                                  c.pfaffenbichler Level 9

                                  Either adapt the Script or adapt the File’s layer- and folder-structure like this:

                                  layersAndGroupsScr.jpg

                                  • 17. Re: How to Export JPG files Scripting Automatically
                                    saranr37921948 Level 1

                                    thank you very much is working

                                     

                                    It is possible this layer structure working the script?

                                     

                                    you understand my English

                                     

                                    Sorry for my bad english.

                                     

                                    I appreciate your help!

                                     

                                    Screen Shot 2017-07-21 at 8.04.44 PM.png

                                    • 18. Re: How to Export JPG files Scripting Automatically
                                      JJMack Most Valuable Participant

                                      If all you want is a shadow  for the shirt why not add a drop shadow layer style on the garment group why add unnecessary complexity. Removing the Art group simplified the scripting required  and the group itself served no real useful function and the structure you now show would most likely not even work the shadow layer you show if made visible would be clipped by the logo visible in the Art group and overlay the logo.

                                       

                                      One of the reasons I did not want to program the script was I could not download your psd without allowing that site to use cookies on my machine.

                                       

                                      With only top level groups the script process required is the loop within a loop I wrote about. Adding more group levels would complicate the scripting required. All the the ART group does is allow you to collapse you layers pallets and hide the layers that you have to see to manipulate their visibility. The ART Group add complexity you do not need.

                                       

                                      You want an automate process to be as simple as it can be. The script will be easier to design and write and require less code and perform better because there is less code required..

                                      • 19. Re: How to Export JPG files Scripting Automatically
                                        saranr37921948 Level 1

                                        this is for the Test file PSD file link

                                        Test File.psd - Google Drive

                                        • 20. Re: How to Export JPG files Scripting Automatically
                                          JJMack Most Valuable Participant

                                          OK I downloaded the file and look at it.  The Art group unifies the color groups and the clipped low opacity multiply neural shirt basically add an gradient overlay onto the logo.   The Art Group adds complexity to the document structure and as does the shadow layer. Both add complexity to any atomated process.

                                           

                                          IMO there are alway more the one way to make a composite.  I want to remind you. You want to keep things as simple as posible if you want to automate the process. For a layer to be visible the group it is in must also be visible.  So if you remove your shadow layer move the color goup out of the art group and delete the art group you have a much less complex structure. IMO you can get your shadow by simply adding a gradient overlay layer style to the color groups.

                                           

                                          The script handed to you will then do what you want.

                                          Capture.jpg

                                          • 21. Re: How to Export JPG files Scripting Automatically
                                            saranr37921948 Level 1

                                            layer comp working and good

                                             

                                            why scripting is not working?

                                             

                                            please advise

                                            • 23. Re: How to Export JPG files Scripting Automatically
                                              saranr37921948 Level 1

                                              I don't know understand sir

                                              • 24. Re: How to Export JPG files Scripting Automatically
                                                c.pfaffenbichler Level 9

                                                // if group of same name as layer exists save jpg of combinations of layer with each layer in group except if the layer is situated in the group;

                                                // 2017, use it at your own risk;

                                                #target photoshop

                                                if (app.documents.length > 0) {

                                                // jpg options;

                                                var jpegOptions = new JPEGSaveOptions();

                                                jpegOptions.quality = 9;

                                                jpegOptions.embedColorProfile = true;

                                                jpegOptions.matte = MatteType.NONE;

                                                var myDocument = activeDocument;

                                                var theName= myDocument.name.match(/(.*)\.[^\.]+$/)[1];

                                                var thePath = myDocument.path;

                                                // get layers and groupd;

                                                var theArrays = getLayerAndGroupsNamesAndIDs();

                                                var theLayers = theArrays[0];

                                                var theGroups = theArrays[1];

                                                // hide layers;

                                                showHideByIdentifier (theLayers, false);

                                                // show groups;

                                                showHideByIdentifier (theGroups, true);

                                                // compare layer names to group names;

                                                for (var m = 0; m < theLayers.length; m++) {

                                                var thisName = theLayers[m][0];

                                                selectLayerByID(theLayers[m][1], false);

                                                var thisLayer = myDocument.activeLayer;

                                                thisLayer.visible = true;

                                                for (var n = 0; n < theGroups.length; n++) {

                                                // if group has same name as layer;

                                                if (thisName == theGroups[n][0]) {

                                                  selectLayerByID(theGroups[n][1],false);

                                                  var thisGroup = myDocument.activeLayer;

                                                // save one copy per layer in group;

                                                  for (var o = 0; o < thisGroup.layers.length; o++) {

                                                  thisGroup.layers[o].visible = true;

                                                  myDocument.saveAs((new File(thePath+"/"+theName+"_"+theGroups[n][0]+"_"+String(o)+".jpg")),jpegOptions,true);

                                                  thisGroup.layers[o].visible = false;

                                                  }

                                                  }

                                                }

                                                myDocument.activeLayer = thisLayer;

                                                thisLayer.visible = false;

                                                };

                                                };

                                                ////////////////////////////////////

                                                function getLayerAndGroupsNamesAndIDs () {

                                                // the file;

                                                var myDocument = app.activeDocument;

                                                // get number of layers;

                                                var ref = new ActionReference();

                                                ref.putEnumerated( charIDToTypeID("Dcmn"), charIDToTypeID("Ordn"), charIDToTypeID("Trgt") );

                                                var applicationDesc = executeActionGet(ref);

                                                var theNumber = applicationDesc.getInteger(stringIDToTypeID("numberOfLayers"));

                                                // process the layers;

                                                var theLayers = new Array;

                                                var theGroups = new Array;

                                                for (var m = 0; m <= theNumber; m++) {

                                                try {

                                                var ref = new ActionReference();

                                                ref.putIndex( charIDToTypeID( "Lyr " ), m);

                                                var layerDesc = executeActionGet(ref);

                                                var layerSet = typeIDToStringID(layerDesc.getEnumerationValue(stringIDToTypeID("layerSection")));

                                                var isBackground = layerDesc.getBoolean(stringIDToTypeID("background"));

                                                // if not layer group collect values;

                                                if (layerSet != "layerSectionEnd" && layerSet != "layerSectionStart" && isBackground != true) {

                                                var theName = layerDesc.getString(stringIDToTypeID('name'));

                                                var theID = layerDesc.getInteger(stringIDToTypeID('layerID'));

                                                theLayers.push([theName, theID])

                                                };

                                                // if  layer group start;

                                                if (layerSet == "layerSectionStart") {

                                                var theName = layerDesc.getString(stringIDToTypeID('name'));

                                                var theID = layerDesc.getInteger(stringIDToTypeID('layerID'));

                                                theGroups.push([theName, theID])

                                                };

                                                }

                                                catch (e) {};

                                                };

                                                /*alert (theLayers.join("\n"));

                                                alert (theGroups.join("\n"));*/

                                                return [theLayers, theGroups]

                                                };

                                                // based on code by mike hale, via paul riggott;

                                                function selectLayerByID(id,add){

                                                add = undefined ? add = false:add

                                                var ref = new ActionReference();

                                                    ref.putIdentifier(charIDToTypeID("Lyr "), id);

                                                    var desc = new ActionDescriptor();

                                                    desc.putReference(charIDToTypeID("null"), ref );

                                                       if(add) desc.putEnumerated( stringIDToTypeID( "selectionModifier" ), stringIDToTypeID( "selectionModifierType" ), stringIDToTypeID( "addToSelection" ) );

                                                      desc.putBoolean( charIDToTypeID( "MkVs" ), false );

                                                   try{

                                                    executeAction(charIDToTypeID("slct"), desc, DialogModes.NO );

                                                }catch(e){

                                                alert(e.message);

                                                }

                                                };

                                                // by mike hale, via paul riggott;

                                                // http://forums.adobe.com/message/1944754#1944754

                                                function selectLayerByIndex(index,add){

                                                add = undefined ? add = false:add

                                                var ref = new ActionReference();

                                                    ref.putIndex(charIDToTypeID("Lyr "), index);

                                                    var desc = new ActionDescriptor();

                                                    desc.putReference(charIDToTypeID("null"), ref );

                                                       if(add) desc.putEnumerated( stringIDToTypeID( "selectionModifier" ), stringIDToTypeID( "selectionModifierType" ), stringIDToTypeID( "addToSelection" ) );

                                                      desc.putBoolean( charIDToTypeID( "MkVs" ), false );

                                                   try{

                                                    executeAction(charIDToTypeID("slct"), desc, DialogModes.NO );

                                                }catch(e){

                                                alert(e.message);

                                                }

                                                };

                                                ////// show or hide layers by id //////

                                                function showHideByIdentifier (theLayers, show) {

                                                for (var x = 0; x < theLayers.length; x++) {

                                                if (show == true) {var idShw = charIDToTypeID( "Shw " )}

                                                else {var idShw = charIDToTypeID( "Hd  " )};

                                                    var desc3 = new ActionDescriptor();

                                                        var list2 = new ActionList();

                                                            var ref2 = new ActionReference();

                                                            ref2.putIdentifier( charIDToTypeID( "Lyr " ), theLayers[x][1] );

                                                        list2.putReference( ref2 );

                                                    desc3.putList( charIDToTypeID( "null" ), list2 );

                                                executeAction( idShw, desc3, DialogModes.NO );

                                                };

                                                };

                                                • 25. Re: How to Export JPG files Scripting Automatically
                                                  saranr37921948 Level 1

                                                  thank you very much

                                                   

                                                  please check your Script this files

                                                  This is for the Test file PSD file link

                                                  Test File.psd - Google Drive

                                                   

                                                  Screen Shot 2017-07-24 at 11.24.27 AM.png

                                                  • 26. Re: How to Export JPG files Scripting Automatically
                                                    c.pfaffenbichler Level 9

                                                    There is a Layer named »shadow« Clipping Masked to the Group named »Art«.

                                                    It is disregarded as it had not been present in the original screenshot.

                                                     

                                                    I posted the Script in an open and editable form, you can edit it however you see fit, including settings that Layer’s visible-property to true before running the for-clause that compares Layer- and Group-names.

                                                    • 27. Re: How to Export JPG files Scripting Automatically
                                                      saranr37921948 Level 1

                                                      sorry you already finished  99.5 % pending just 0.5 % kindly do this only finally 

                                                       

                                                      I don't know that kind of scripting 

                                                       

                                                      thank you very much

                                                      • 28. Re: How to Export JPG files Scripting Automatically
                                                        c.pfaffenbichler Level 9

                                                        activeDocument.layers.getByName("shadow").visible = true;

                                                        1 person found this helpful
                                                        • 29. Re: How to Export JPG files Scripting Automatically
                                                          saranr37921948 Level 1

                                                          sorry

                                                           

                                                          I don't know where is put this code

                                                           

                                                          thank you very much

                                                          • 32. Re: How to Export JPG files Scripting Automatically
                                                            c.pfaffenbichler Level 9

                                                            So I assume you figured out where to insert the line?

                                                            • 33. Re: How to Export JPG files Scripting Automatically
                                                              saranr37921948 Level 1

                                                              I insert two lines

                                                               

                                                              I don't know exactly this is correct position kindly advise

                                                               

                                                              one more doubt export the JPEG files any change for file names possible

                                                               

                                                              the JPG Files name change possible which coding I will change?

                                                               

                                                              Screen Shot 2017-07-24 at 5.10.40 PM.png

                                                              • 34. Re: How to Export JPG files Scripting Automatically
                                                                c.pfaffenbichler Level 9

                                                                Inserting the line once after

                                                                showHideByIdentifier (theGroups, true);

                                                                should suffice.

                                                                In the line

                                                                myDocument.saveAs((new File(thePath+"/"+theName+"_"+theGroups[n][0]+"_"+String(o)+".jpg")),jpegOptions,true);

                                                                you can make changes as to how the files will be named.

                                                                1 person found this helpful
                                                                • 35. Re: How to Export JPG files Scripting Automatically
                                                                  saranr37921948 Level 1

                                                                  how to do this scrip for Necktag group , like layers (shadow)

                                                                   

                                                                  Screen Shot 2017-07-24 at 5.42.32 PM.png

                                                                  • 36. Re: How to Export JPG files Scripting Automatically
                                                                    saranr37921948 Level 1

                                                                    I edit the coding

                                                                     

                                                                    File name I add layer name also is not working

                                                                    Screen Shot 2017-07-24 at 8.24.36 PM.png

                                                                     

                                                                    // save one copy per layer in group;

                                                                      for (var o = 0; o < thisGroup.layers.length; o++) {

                                                                      thisGroup.layers[o].visible = true;

                                                                      myDocument.saveAs((new File(thePath+"/"+theName+"_"+theGroups[n][0]+"_"+theLayer[n][0]+"_"+String(o)+".jpg")),jpegOptions,true);

                                                                    thisGroup.layers[o].visible = false;

                                                                    • 37. Re: How to Export JPG files Scripting Automatically
                                                                      saranr37921948 Level 1

                                                                      How create the group folder taken in Garments layer names in script

                                                                      example

                                                                       

                                                                      Screen Shot 2017-08-02 at 5.34.58 PM.png

                                                                       

                                                                      kindly edit the script thank you for your help c.pfaffenbichler

                                                                       

                                                                       

                                                                      // if group of same name as layer exists save jpg of combinations of layer with each layer in group except if the layer is situated in the group;

                                                                      // 2017, use it at your own risk;

                                                                      #target photoshop

                                                                      if (app.documents.length > 0) {

                                                                      // jpg options;

                                                                      var jpegOptions = new JPEGSaveOptions();

                                                                      jpegOptions.quality = 9;

                                                                      jpegOptions.embedColorProfile = true;

                                                                      jpegOptions.matte = MatteType.NONE;

                                                                      var myDocument = activeDocument;

                                                                      var theName= myDocument.name.match(/(.*)\.[^\.]+$/)[1];

                                                                      var thePath = myDocument.path;

                                                                      // get layers and groupd;

                                                                      var theArrays = getLayerAndGroupsNamesAndIDs();

                                                                      var theLayers = theArrays[0];

                                                                      var theGroups = theArrays[1];

                                                                      // hide layers;

                                                                      showHideByIdentifier (theLayers, false);

                                                                      // show groups;

                                                                      showHideByIdentifier (theGroups, true);

                                                                      // compare layer names to group names;

                                                                      for (var m = 0; m < theLayers.length; m++) {

                                                                      var thisName = theLayers[m][0];

                                                                      selectLayerByID(theLayers[m][1], false);

                                                                      var thisLayer = myDocument.activeLayer;

                                                                      thisLayer.visible = true;

                                                                      for (var n = 0; n < theGroups.length; n++) {

                                                                      // if group has same name as layer;

                                                                      if (thisName == theGroups[n][0]) {

                                                                        selectLayerByID(theGroups[n][1],false);

                                                                        var thisGroup = myDocument.activeLayer;

                                                                      // save one copy per layer in group;

                                                                        for (var o = 0; o < thisGroup.layers.length; o++) {

                                                                        thisGroup.layers[o].visible = true;

                                                                        myDocument.saveAs((new File(thePath+"/"+theName+"_"+theGroups[n][0]+"_"+String(o)+".jpg")),jpegOptions,true);

                                                                        thisGroup.layers[o].visible = false;

                                                                        }

                                                                        }

                                                                      }

                                                                      myDocument.activeLayer = thisLayer;

                                                                      thisLayer.visible = false;

                                                                      };

                                                                      };

                                                                      ////////////////////////////////////

                                                                      function getLayerAndGroupsNamesAndIDs () {

                                                                      // the file;

                                                                      var myDocument = app.activeDocument;

                                                                      // get number of layers;

                                                                      var ref = new ActionReference();

                                                                      ref.putEnumerated( charIDToTypeID("Dcmn"), charIDToTypeID("Ordn"), charIDToTypeID("Trgt") );

                                                                      var applicationDesc = executeActionGet(ref);

                                                                      var theNumber = applicationDesc.getInteger(stringIDToTypeID("numberOfLayers"));

                                                                      // process the layers;

                                                                      var theLayers = new Array;

                                                                      var theGroups = new Array;

                                                                      for (var m = 0; m <= theNumber; m++) {

                                                                      try {

                                                                      var ref = new ActionReference();

                                                                      ref.putIndex( charIDToTypeID( "Lyr " ), m);

                                                                      var layerDesc = executeActionGet(ref);

                                                                      var layerSet = typeIDToStringID(layerDesc.getEnumerationValue(stringIDToTypeID("layerSection")));

                                                                      var isBackground = layerDesc.getBoolean(stringIDToTypeID("background"));

                                                                      // if not layer group collect values;

                                                                      if (layerSet != "layerSectionEnd" && layerSet != "layerSectionStart" && isBackground != true) {

                                                                      var theName = layerDesc.getString(stringIDToTypeID('name'));

                                                                      var theID = layerDesc.getInteger(stringIDToTypeID('layerID'));

                                                                      theLayers.push([theName, theID])

                                                                      };

                                                                      // if  layer group start;

                                                                      if (layerSet == "layerSectionStart") {

                                                                      var theName = layerDesc.getString(stringIDToTypeID('name'));

                                                                      var theID = layerDesc.getInteger(stringIDToTypeID('layerID'));

                                                                      theGroups.push([theName, theID])

                                                                      };

                                                                      }

                                                                      catch (e) {};

                                                                      };

                                                                      /*alert (theLayers.join("\n"));

                                                                      alert (theGroups.join("\n"));*/

                                                                      return [theLayers, theGroups]

                                                                      };

                                                                      // based on code by mike hale, via paul riggott;

                                                                      function selectLayerByID(id,add){

                                                                      add = undefined ? add = false:add

                                                                      var ref = new ActionReference();

                                                                          ref.putIdentifier(charIDToTypeID("Lyr "), id);

                                                                          var desc = new ActionDescriptor();

                                                                          desc.putReference(charIDToTypeID("null"), ref );

                                                                             if(add) desc.putEnumerated( stringIDToTypeID( "selectionModifier" ), stringIDToTypeID( "selectionModifierType" ), stringIDToTypeID( "addToSelection" ) );

                                                                            desc.putBoolean( charIDToTypeID( "MkVs" ), false );

                                                                         try{

                                                                          executeAction(charIDToTypeID("slct"), desc, DialogModes.NO );

                                                                      }catch(e){

                                                                      alert(e.message);

                                                                      }

                                                                      };

                                                                      // by mike hale, via paul riggott;

                                                                      // http://forums.adobe.com/message/1944754#1944754

                                                                      function selectLayerByIndex(index,add){

                                                                      add = undefined ? add = false:add

                                                                      var ref = new ActionReference();

                                                                          ref.putIndex(charIDToTypeID("Lyr "), index);

                                                                          var desc = new ActionDescriptor();

                                                                          desc.putReference(charIDToTypeID("null"), ref );

                                                                             if(add) desc.putEnumerated( stringIDToTypeID( "selectionModifier" ), stringIDToTypeID( "selectionModifierType" ), stringIDToTypeID( "addToSelection" ) );

                                                                            desc.putBoolean( charIDToTypeID( "MkVs" ), false );

                                                                         try{

                                                                          executeAction(charIDToTypeID("slct"), desc, DialogModes.NO );

                                                                      }catch(e){

                                                                      alert(e.message);

                                                                      }

                                                                      };

                                                                      ////// show or hide layers by id //////

                                                                      function showHideByIdentifier (theLayers, show) {

                                                                      for (var x = 0; x < theLayers.length; x++) {

                                                                      if (show == true) {var idShw = charIDToTypeID( "Shw " )}

                                                                      else {var idShw = charIDToTypeID( "Hd  " )};

                                                                          var desc3 = new ActionDescriptor();

                                                                              var list2 = new ActionList();

                                                                                  var ref2 = new ActionReference();

                                                                                  ref2.putIdentifier( charIDToTypeID( "Lyr " ), theLayers[x][1] );

                                                                              list2.putReference( ref2 );

                                                                          desc3.putList( charIDToTypeID( "null" ), list2 );

                                                                      executeAction( idShw, desc3, DialogModes.NO );

                                                                      };

                                                                      };

                                                                      • 38. Re: How to Export JPG files Scripting Automatically
                                                                        c.pfaffenbichler Level 9

                                                                        The Groups appear to be empty so I fail to see the use.