4 Replies Latest reply on Jan 19, 2015 1:34 PM by dig_dig_dig

    File path returning NaN

    BenthicEye

      Hello!

      I'm currently involved with a project that requires analysis of images from several hundred stations along the Alaskan seafloor.  Each station has three top down (PV) images of the seafloor taken and three images (SPI) that are taken below the seafloor (it's pretty cool).

       

      It is often necessary to compare the SPI and PV images side by side in order to make a proper assessment of the seafloor at each station.  I find myself opening the SPI images most often and then needing to dig around in the PV folder to find the appropriate image pairings.  This can be time consuming so I've decided to write a script that will query my active document for a name and path and then use that information automatically open up its counterpart.

       

      I'm close to getting it working but I keep returning an error that says "error opening NaN/PV/CH_PV_Analysis/CH-14B1-PV-41-a.psd".

       

      The error returns a perfect file path from "/PV/" onward but for some reasons begins the path with "NaN" when it should pull my file path.   Why is this?  I'm using the same line of code for another automation script on this project and can't seem to figure out why it's behaving differently here. 

       

      I should mention as well that I'm accessing the files via a server.

       

      My code looks like this:

       

      // call the current document

      var srcDoc = app.activeDocument;

       

       

      // ask user input for PV replicate letter

      var repLetter =prompt("Which PV replicate would you like to open? (A.. B.. C.. etc.)");

       

       

      // get the info out of the source doc

      var fileName = srcDoc.name;

      var docName = fileName.substring(0,fileName.length -4);

      var filePath = srcDoc.path.toString();

      var fileExt = fileName.substring(fileName.length -4, fileName.length);

       

       

      var nameCheck = fileName.substring(0,fileName.indexOf("CH-14B1-SPI-"));

       

       

      if (nameCheck <1)

      {

         var fileNum = fileName.substring(12,fileName.length -5) + repLetter;

         // no underscore so we need to open it's namesake

         // alert(nameCheck)

         var filePair = filePath -"/SPI/CH_SPI_Analysis/" + "/PV/CH_PV_Analysis/" + "CH-14B1-SPI-PV-" + fileNum + fileExt;

         openThisFile(filePair)

         }

       

       

      function openThisFile(masterFileNameAndPath)

      {

      var fileRef = new File(masterFileNameAndPath)

      if (fileRef.exists)

      //open that doc

      {

          app.open(fileRef);

      }

      else

      {

          alert("error opening " + masterFileNameAndPath)

      }

      }