3 Replies Latest reply on Nov 12, 2014 6:28 AM by Pedro Cortez Marques

    doc.layerSets.getByName fails randomly




      after upgrading from CS6 to CC last week one of our scripts broke. Basically the script opens multiple files and merges them into a single one, during that several calls to

      doc.layerSets.getByName("layerName") are made (The layer set name is "ANIMATION" and it's one of four sets). At some point this call will fail with a message like: "General Photoshop error. The function is possibly not available in this Version" (Translated from German, so it might not be this exact message). It seems to fail randomly depending on which files we run the script with and I can't make sense of it at all. Is anyone else seeing this?


      Any help would be appreciated.


        • 1. Re: doc.layerSets.getByName fails randomly
          Pedro Cortez Marques Level 3

          I'm using this because it avoids that error. Even is there would be another way of avoiding it, I think this is the simplest and the best because it search any layer name inside or outside any group (layerSet)


          // this will search all artLayers outside or inside any layerSet (group). Returns true or false depending on layer name search success
          function makeLayerActiveByName(nm) {  
              function cTID(s) { return app.charIDToTypeID(s); };  
              try {  
                  var desc5 = new ActionDescriptor();  
                  var ref4 = new ActionReference();  
                  ref4.putName( cTID('Lyr '),  nm);  
                  desc5.putReference( cTID('null'), ref4 );  
                  desc5.putBoolean( cTID('MkVs'), false );  
                  executeAction( cTID('slct'), desc5, DialogModes.NO );  
                  return true;  
              } catch (e) {  
              return false;  
          • 2. Re: Re: doc.layerSets.getByName fails randomly
            mschiessl Level 1

            Thanks for your answer, unfortunately I actually need the child LayerSet to do further processing with it, just making a layer active isn't enough. I've now tried accessing it trough an index:


            for (var i = 0; i < layerSet.length; i++) {
              if (name == parent[i].name) {
                return parent[i];


            but it gives me the same results. Interestingly, the second and fourth LayerSet can be accessed through getByName and through indexing with []. Only the first gives me "General Photoshop Error, this function may not be available in this version.." and the third one gives me "Error: Element doesn't exist".


            Are you aware of any other way to work around this?


            Thank you very much


            • 3. Re: Re: Re: doc.layerSets.getByName fails randomly
              Pedro Cortez Marques Level 3

              If your layerSet is a document child and not a child of another layerSet, this should work:

              (it avoids the error that getByName() returns when there is no name found.


              var setAnimation = getChildLayerSetName('ANIMATION');
              if (setAnimation != undefined) {
                  // create here your routine inside the founded layerSet
                  for (var a=0; a<setAnimation.artLayers.length ; a++) {
              // returns the layerSet object, otherwise returns 'undefined'
              function getChildLayerSetName(parentLayerSet) {
                  for (var a=0; a<app.activeDocument.layerSets.length ; a++) {
                      if (String(app.activeDocument.layerSets[a].name) == parentLayerSet) {
                          return app.activeDocument.layerSets[a];