1 Reply Latest reply on Jan 14, 2014 2:36 PM by Prails.deisgn

    Dynamic Save File Path

    Prails.deisgn

      Hey Everyone,

       

      So I deal with a lot of files each day that need to be saved according to their lead code, meaning that there is a folder that holds thousands of sub folders that have the same name as this lead code on a server.

       

      So since I have the lead code in the file name I'm trying to use that in conjunction with the file path to tell illustrator where to save it with Javascript. Also the idea of a dynamic save path is awesome to me.

       

      Here's what I've got so far, it's not working yet but I feel like I'm close.

       

       

      /*/////////////////////////////////////////////////////////////////////////////
      ////////////////////////////////////////////////////////////////////////////////
      Dynamic Save Path////////////////////////////////////////////////////////////////////////////////
      /////////////////////////////////////////////////////////////////////////////*/
      #target illustrator
      
      ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
      ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
      var sourceDoc = app.activeDocument;
      var sourceName =sourceDoc.name;
      var customerNum = sourceName.substring(0, sourceName.length - 8)
          customerNum
          sourceName = sourceName.substring(0, sourceName.length - 3)
          
      
      //alert(sourceName)
      ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
      alert(customerNum + " Customer # saved")
      alert(sourceName + " File name saved") //end
      ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
      
      
      /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
      /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
      var doc = app.activeDocument;
      var doc_Path = File("I:\GRAPHICS"+ "/" + customerNum);
      
      var substituir_Path = doc_Path+ "/" + customerNum;
      //alert("sourceName: "+sourceName+"\nsourceDoc_Path: "+doc_Path+"\nsubstituir_Path: "+substituir_Path);
      
      function SaveFileAsFXG (dest) {
          if ( app.documents.length > 0 ) {
              var saveOptions = new FXGSaveOptions();
              var fxgDoc = new File(dest);
              app.activeDocument.saveAs( fxgDoc, saveOptions );
          }
      }
      
      var destFilePath = substituir_Path;
      SaveFileAsFXG (destFilePath);
      /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
      alert("done!") //end
      /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
      
      
        • 1. Re: Dynamic Save File Path
          Prails.deisgn Level 1

          I figured it out, I had it removing too many characters. I can get away with hardcoding this in my script because of how we name files where I work. also I realized I had a left over part in there that I didn't need.

           

          I also got rid of the dividers to make it easeir to read here online

           

           

           

          #target illustrator

           

           

          var sourceDoc = app.activeDocument;

          var sourceName =sourceDoc.name;

          var customerNum = sourceName.substring(0, sourceName.length - 7)

              customerNum

              sourceName = sourceName.substring(0, sourceName.length - 3)

           

           

           

          alert(customerNum + " Customer # saved")

          alert(sourceName + " File name saved") //end

           

           

          var doc = app.activeDocument;

          var doc_Path = File("I:\GRAPHICS"+ "/" + customerNum);

           

           

          function SaveFileAsFXG (dest) {

              if ( app.documents.length > 0 ) {

                  var saveOptions = new FXGSaveOptions();

                  var fxgDoc = new File(dest);

                  app.activeDocument.saveAs( fxgDoc, saveOptions );

              }

          }

           

          SaveFileAsFXG (doc_Path);

           

          alert("done!") //end