1 Reply Latest reply on Oct 28, 2010 9:13 AM by deerowbear

    opening a document with a dialog open

    deerowbear Level 1

      I am trying to open a document with a window open created by javascript, but I get an error when the window is open and I try to open the document. See attached:

      error.JPG

       

       

      Is there no way to have a window open and the application open a document at the same time?

       

      See code, do you see any errors:

       

      #target "InDesign-7.0"

      #strict on

      UserInteractionLevels.neverInteract;

      var dlg;

      /******************************

      Validate the input by the user

      ******************************/

      function validate()

      {

           if(dlg.iPanel.inputPath.text == "")

          {

                  alert("Error, please define a directory to convert.");

                  return -1;

          }

          if(dlg.oPanel.outputPath.text == "")

          {

                  alert("Error, please define an output directory.");

                  return -1;

          }

          return 0

      }

      /*************************

      define user text file

      input to define file path

      **************************/

      function getInput()

      {

          var input_folder = Folder.selectDialog( 'Select the directory where you wish to open the files: ', '' );

          if (input_folder != null)

          {

              this.parent.inputPath.text = input_folder.toString();

              this.parent.inputPath.enabled = false;

          }

      }

      /*************************

      define user output path

      **************************/

      function getOutput()

      {

      var output = Folder.selectDialog( 'Select the directory where you wish to output the files: ', '' );

      try

      {

      this.parent.outputPath.text = output.toString();

      }

      catch(e)

      {

      alert("Path is undefined");

      }

      this.parent.outputPath.enabled = false;

      return;

      }

      /*************************

      function for writting out

      errors.

      **************************/

      function log_status(msg, file)

      {

      if(errorFile.exists == true)

      {

      alert("File  exist")

      errorFile.open("e", "", "")

      errorFile.write(msg + "\n");

      errorFile.close();

      }

      else

      {

      alert("File no exists");

      errorFile.open("w", "", "")

      errorFile.write(msg+ "\n") ;

      errorFile.close();

      }

      return;

      }

      /*************************

      open indesign file

      **************************/

      function openFile(file)

      {

          try

          {

          app.open(File(file));

          }

          catch(e)

          {

          alert(e);   

          }

      return;

      }

      /*************************

      Export PDF

      **************************/

      function exportPDF(output)

      {

       

      }

      /***********************************

      main function to convert

      indesign files to pdf

      ***********************************/

      function main()

      {

          var errorFileObj = new File("c:/errorFile.txt");

          var successFileObj = new File("c:/successFile.txt");

          errorFileObj.open("w", "", "");

          successFileObj.open("w", "", "");

          if(validate() == -1)

              return;

          var input_folder = new Folder(dlg.iPanel.inputPath.text);

          files_array = input_folder.getFiles( '*.indd' );

       

          //dlg.close(1);

       

          for(var i = 0; i < files_array.length; i++)

          {

              try

              {

                  openFile(files_array[i]);

              }

              catch(e)

              {

                  errorFileObj.write(files_array[i]+ "\n") ;

                  continue;

              }

              try

              {

                  //exportPDF(output);

                  successFileObj.write(files_array[i]+ "\n") ;

              }

              catch(e)

              {

                  errorFileObj.write(files_array[i]+ "\n") ;

                  continue;

              }

              alert(files_array[i]);

          }

          successFileObj.close();

          errorFileObj.close();

          alert ("Files finished converting");

      }

      /***********************************

      create an instance of GUI for

      user input

      ***********************************/

      function createGUI()

      {

      dlg = new Window('dialog', 'Indesign to PDF:', [100,100,480,300]);

      dlg.iPanel = dlg.add('panel',[5,10,375,80], 'Define Input');

      dlg.iPanel.inputText = dlg.iPanel.add('statictext', [10,12,125,25], 'Browse for directory:');

      dlg.iPanel.inputBtn = dlg.iPanel.add('button', [10,30,110,50], 'Browse');

      dlg.iPanel.inputPath = dlg.iPanel.add('edittext', [120,30,350,50], '');

      dlg.iPanel.inputBtn.onClick = getInput;

      dlg.oPanel = dlg.add('panel',[5,80,375,150], 'Define Output');

      dlg.oPanel.outputText = dlg.oPanel.add('statictext', [10,12,165,25], 'Browse for output directory:');

      dlg.oPanel.outputBtn = dlg.oPanel.add('button', [10,30,110,50], 'Browse');

      dlg.oPanel.outputPath = dlg.oPanel.add('edittext', [120,30,350,50], '');

      dlg.oPanel.outputBtn.onClick = getOutput;

      dlg.startBtn = dlg.add('button', [225,160,375,185], 'Start Conversion');

      dlg.startBtn.onClick = main;

      dlg.show();

      }

      createGUI();//entry point for the script

        • 1. Re: opening a document with a dialog open
          deerowbear Level 1

          Okay, this works....LAME....

           

           

          #target "InDesign-7.0"

          #strict on

          UserInteractionLevels.neverInteract;

          var dlg;

          var files_array;

          /******************************

          Validate the input by the user

          ******************************/

          function validate()

          {

               if(dlg.iPanel.inputPath.text == "")

              {

                      alert("Error, please define a directory to convert.");

                      return -1;

              }

              if(dlg.oPanel.outputPath.text == "")

              {

                      alert("Error, please define an output directory.");

                      return -1;

              }

              return 0

          }

          /*************************

          define user text file

          input to define file path

          **************************/

          function getInput()

          {

              var input_folder = Folder.selectDialog( 'Select the directory where you wish to open the files: ', '' );

              if (input_folder != null)

              {

                  this.parent.inputPath.text = input_folder.toString();

                  this.parent.inputPath.enabled = false;

              }

          }

          /*************************

          define user output path

          **************************/

          function getOutput()

          {

          var output = Folder.selectDialog( 'Select the directory where you wish to output the files: ', '' );

          try

          {

          this.parent.outputPath.text = output.toString();

          }

          catch(e)

          {

          alert("Path is undefined");

          }

          this.parent.outputPath.enabled = false;

          return;

          }

          /*************************

          function for writting out

          errors.

          **************************/

          function log_status(msg, file)

          {

          if(errorFile.exists == true)

          {

          alert("File  exist")

          errorFile.open("e", "", "")

          errorFile.write(msg + "\n");

          errorFile.close();

          }

          else

          {

          alert("File no exists");

          errorFile.open("w", "", "")

          errorFile.write(msg+ "\n") ;

          errorFile.close();

          }

          return;

          }

          /*************************

          open indesign file

          **************************/

          function openFile(files_array)

          {

              for(var i = 0; i < files_array.length; i++)

              {

                  try

                  {

                      app.open(File(files_array[i]));

                  }

                  catch(e)

                  {

                      alert(e);

                      continue;

                  }

              }

          return;

          }

          /*************************

          Export PDF

          **************************/

          function exportPDF(output)

          {

           

          }

          /***********************************

          main function to convert

          indesign files to pdf

          ***********************************/

          function main()

          {

              var errorFileObj = new File("c:/errorFile.txt");

              var successFileObj = new File("c:/successFile.txt");

              errorFileObj.open("w", "", "");

              successFileObj.open("w", "", "");

              if(validate() == -1)

                  return;

              var input_folder = new Folder(dlg.iPanel.inputPath.text);

           

              files_array = input_folder.getFiles( '*.indd' );

              dlg.close ();

              //dlg.destroy();

              /*

              for(var i = 0; i < files_array.length; i++)

              {

                  try

                  {

                      openFile(files_array[i]);

                  }

                  catch(e)

                  {

                      errorFileObj.write(files_array[i]+ "\n") ;

                      continue;

                  }

                  try

                  {

                      //exportPDF(output);

                      successFileObj.write(files_array[i]+ "\n") ;

                  }

                  catch(e)

                  {

                      errorFileObj.write(files_array[i]+ "\n") ;

                      continue;

                  }

                  alert(files_array[i]);

              }

              successFileObj.close();

              errorFileObj.close();

              alert ("Files finished converting");

              */

          }

          /***********************************

          create an instance of GUI for

          user input

          ***********************************/

          function createGUI()

          {

          dlg = new Window('dialog', 'Indesign to PDF:', [100,100,480,300]);

          dlg.iPanel = dlg.add('panel',[5,10,375,80], 'Define Input');

          dlg.iPanel.inputText = dlg.iPanel.add('statictext', [10,12,125,25], 'Browse for directory:');

          dlg.iPanel.inputBtn = dlg.iPanel.add('button', [10,30,110,50], 'Browse');

          dlg.iPanel.inputPath = dlg.iPanel.add('edittext', [120,30,350,50], '');

          dlg.iPanel.inputBtn.onClick = getInput;

          dlg.oPanel = dlg.add('panel',[5,80,375,150], 'Define Output');

          dlg.oPanel.outputText = dlg.oPanel.add('statictext', [10,12,165,25], 'Browse for output directory:');

          dlg.oPanel.outputBtn = dlg.oPanel.add('button', [10,30,110,50], 'Browse');

          dlg.oPanel.outputPath = dlg.oPanel.add('edittext', [120,30,350,50], '');

          dlg.oPanel.outputBtn.onClick = getOutput;

          dlg.startBtn = dlg.add('button', [225,160,375,185], 'Start Conversion');

          dlg.startBtn.onClick = main;

          dlg.show();

          }

          createGUI();//entry point for the script

          openFile(files_array);