title: Error in Photoshop Script?
body: <p>Hi I have a photoshop script for creating permutations of layers. So far I have my PSD document saved to the desktop.</p>
  
  <p>The photoshop file consists of the 8 Layers </p>
  
  <pre><code>    &lt;Layer 1&gt;
      &lt;Layer 2&gt;
      &lt;Layer 3&gt;
      &lt;Layer 4&gt;
      &lt;Layer 5&gt;
      &lt;Layer 6&gt;
      &lt;Layer 7&gt;
      &lt;Layer 8&gt;
  </code></pre>
  
  <p>Named like exactly like above </p>
  
  <p>The script is throwing an error :</p>
  
  <p>Error 1302: No Such Element
  Line: 22
  ->   app.activeDocument.artLayers[t-i].visible = false;</p>
  
  <pre><code>#target photoshop
  
  //set pathToSave to C:\ or whatever - make sure it has a \\ (or / on Mac/Linux) on the end
  //if you're on windows, every \ needs to be \\ instead
  var pathToSave = "C:\\temp\\"; 
  
  var a = 1; // number base layers
  var p = 8; // number of layers used for permutations 
  
  main();
  
   function main() {
       var exportInfo = new Object();
          initExportInfo(exportInfo);
  
  var t = app.activeDocument.artLayers.length-1; 
  
  function hideAll() 
  {
      for (var i = a; i &lt; a+p; i++) 
      {
          app.activeDocument.artLayers[t-i].visible = false;
      }
  }
  
  for (var x = a; x &lt; a+p; x++) {
      for (var y = x+1; y &lt; a+p; y++) {
          for (var z = y+1; z &lt; a+p; z++) {
              hideAll();
              app.activeDocument.artLayers[t-x].visible = true;
              app.activeDocument.artLayers[t-y].visible = true;
              app.activeDocument.artLayers[t-z].visible = true;
              saveFile( app.activeDocument, x+'-'+y+'-'+z, exportInfo);
               }
           }  
      }
  }
  
      function initExportInfo(exportInfo)
  {
       exportInfo.destination = new String("");
       exportInfo.fileNamePrefix = new String("untitled_");
       exportInfo.selectionOnly = false;
       exportInfo.fileType = 'jpeg';
       exportInfo.icc = true;
       exportInfo.jpegQuality = 8;
       exportInfo.psdMaxComp = true;
       exportInfo.tiffCompression = TIFFEncoding.NONE;
       exportInfo.tiffJpegQuality = 8;
       exportInfo.pdfEncoding = PDFEncoding.JPEG;
       exportInfo.pdfJpegQuality = 8;
       exportInfo.targaDepth = TargaBitsPerPixels.TWENTYFOUR;
       exportInfo.bmpDepth = BMPDepthType.TWENTYFOUR;
       exportInfo.png24Transparency = true;
       exportInfo.png24Interlaced = false;
       exportInfo.png8Transparency = true;
       exportInfo.png8Interlaced = false;
  
       try {
      exportInfo.destination = Folder(app.activeDocument.fullName.parent).fsName; // destination folder
      var tmp = app.activeDocument.fullName.name;
      exportInfo.fileNamePrefix = decodeURI(tmp.substring(0, tmp.indexOf("."))); // filename body part
  } catch(someError) {
      exportInfo.destination = new String("");
      exportInfo.fileNamePrefix = app.activeDocument.name; // filename body part
       }
   }
  
   function saveFile( docRef, fileNameBody, exportInfo)
   {
       docRef.bitsPerChannel = BitsPerChannelType.EIGHT;
            var saveFile = new File(pathToSave + fileNameBody + ".jpg");
       jpgSaveOptions = new JPEGSaveOptions();
       jpgSaveOptions.embedColorProfile = exportInfo.icc;
       jpgSaveOptions.quality = exportInfo.jpegQuality;
       docRef.saveAs(saveFile, jpgSaveOptions, true, Extension.LOWERCASE);
   }
  </code></pre>
  
  <p>I am using Photoshop CS 6 on Windows 7 x64.</p>