1 Reply Latest reply on Nov 22, 2010 3:37 AM by c.pfaffenbichler

    I could use a pointer in the right direction.

    EDDKBAWILLIAMS Level 1

      I've got a script that performs a certain number of tasks to the currently selected layer... Works perfectly... What I would like to do is expand on this script and have it perform the same tasks on every single visible layer in the document.

       

      Sadly I don't know much of anything about scripting. Any chance I could get someone to point me in the right direction? I would be happy to pay someone to write a little script that would either process every single layer, every visible layer or every named layer and run a particular script.

       

      So I imagine it would be something at the top of the script like this.

       

      NamedLayer="TESTSample"

      RunScript="NameofScripttoRun"

       

      ProcessEveryLayer=False

      ProcessEveryVisibleLayer=True

      ProcessEveryNamedLayer=False

       

       

      So I can manually type in the Name of the Script to be run. If I were to set the ProcessEveryNamedLayer to True then I could also specify the name of the layer with the NamedLayer= option. I would then set the other two layer options to false.

       

      Any takers?

       

      Thanks

       

      Steve Williams

        • 1. Re: I could use a pointer in the right direction.
          c.pfaffenbichler Level 9

          You could use a function like this to collect the layers:

           

          var theLayers = collectLayers(app.activeDocument);

          ////// function collect all layers //////

          function collectLayers (theParent) {

          if (!allLayers) {

          var allLayers = new Array}

          else {};

          for (var m = theParent.layers.length - 1; m >= 0;m--) {

          var theLayer = theParent.layers[m];

          // apply the function to layersets;

          if (theLayer.typename == "ArtLayer") {

          allLayers.push(theLayer)

          }

          else {

          allLayers = allLayers.concat(collectLayers(theLayer))

          // this line includes the layer groups;

          allLayers.push(theLayer);

          }

          };

          return allLayers

          };

           

          Then have a for-operation work through the layers-array.

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

          app.activeDocument.activeLayer = theLayers[m];

          };

           

          But depending on the operation you may not want to work through all Layers, but only through, for example, pixel layers.

          So you could adapt the collectLayers-function to only return layers that fit certain criteria, which you could put into an additional if-clause.