4 Replies Latest reply on May 1, 2012 8:07 AM by Muppet Mark

    [JS][CS5] Clean way to unlock endless sublayers?

    booyajamo

      Hello,

       

      I've written a snippet that will unlock sub of sub layers up to 10 layers deep. It works fine; however I'm wondering if there is a better way to do this? I don't know that 10 is the maximum of sub layers I'll need to unlock but it's a fairly safe guess. I'd like to be more efficient and know that no matter what the layer structure of the file my script has unlocked any and all sublayers.

       

      Is there a different approach or way to think about this problem where you can script for a potentially endless number of sublayers, and subs of subs, etc.?

       

      Thanks!

       

      var doc = app.activeDocument;
      
      
      var layerCount = doc.layers.length;
      for (i=0; i<layerCount; i++) {
          var currentLayerI = doc.layers[i];
          var layerCountII = currentLayerI.layers.length;
          for (ii=0; ii<layerCountII; ii++) {
              var currentLayerII = currentLayerI.layers[ii];
              var layerCountIII = currentLayerII.layers.length;
              for (iii=0; iii<layerCountIII; iii++) {
                  var currentLayerIII = currentLayerII.layers[iii];
                  var layerCountIV = currentLayerIII.layers.length;
                  for (iv=0; iv<layerCountIV; iv++) {
                      var currentLayerIV = currentLayerIII.layers[iv];
                      var layerCountV = currentLayerIV.layers.length;
                      for (v=0; v<layerCountV; v++) {
                          var currentLayerV = currentLayerIV.layers[v];
                          var layerCountVI = currentLayerV.layers.length;
                          for (vi=0; vi<layerCountVI; vi++){
                              var currentLayerVI = currentLayerV.layers[vi];
                              var layerCountVII = currentLayerVI.layers.length;
                              for (vii=0; vii<layerCountVII; vii++) {
                                  var currentLayerVII = currentLayerVI.layers[vii];
                                  var layerCountVIII = currentLayerVII.layers.length;
                                  for (viii=0; viii<layerCountVIII; viii++) {
                                      var currentLayerVIII = currentLayerVII.layers[viii];
                                      var layerCountIX = currentLayerVIII.layers.length;
                                      for (ix=0; ix<layerCountIX; ix++) {
                                          var currentLayerIX = currentLayerVIII.layers[ix];
                                          var layerCountX = currentLayerIX.layers.length;
                                          for (x=0; x<layerCountX; x++) {
                                              var currentLayerX = currentLayerIX.layers[x];
                                              if (currentLayerX.locked == true) {
                                                  currentLayerX.locked = false;
                                                  }
                                              }
                                          if (currentLayerIX.locked == true) {
                                              currentLayerIX.locked = false;
                                              }
                                          }
                                      if (currentLayerVIII.locked == true) {
                                          currentLayerVIII.locked = false;
                                          }
                                      }
                                  if (currentLayerVII.locked == true) {
                                      currentLayerVII.locked = false;
                                      }
                                  }
                              if (currentLayerVI.locked == true) {
                                  currentLayerVI.locked = false;
                                  }
                              }
                          if (currentLayerV.locked == true) {
                              currentLayerV.locked = false;
                              }
                          }
                      if (currentLayerIV.locked == true) {
                          currentLayerIV.locked = false;
                          }
                      }
                  if (currentLayerIII.locked == true) {
                      currentLayerIII.locked = false;
                      }
                  }
              if (currentLayerII.locked== true) {
                  currentLayerII.locked = false;
                  }
              }
          if (currentLayerI.locked == true) {
              currentLayerI.locked = false;
          }
      }