Back

If your email is not recognized and you believe it should be, please contact us.

  • You must be logged in to reply to this topic.Login

ExportAllStories Modified to Include Page Number

Return to Member Forum

  • Author
    Posts
    • #53960
      Joe C
      Member

      Hey Gang,

      I've modified the ExportAllStories script to add a page number to the file name for each exported story. However, after doing some testing the page number is not always correct.

      I made a document with 5 pages and 5 text boxes containing their page numbers so I could move these boxes to different pages to see the page numbers change but this is not always happening.

      For example, I put Box 5 on page 1 so I would expect Page1 StoryID1401.txt to contain “Page 5” but this is not happening.

      Could the page number depend on the page each box was created on? Or is there something wrong with the script?

      This is part of what I added:

      function myExportAllStories(myExportFormat, myFolder){
      for(myCounter = 0; myCounter < app.activeDocument.stories.length; myCounter++){
      myStory = app.activeDocument.stories.item(myCounter);
      myID = myStory.id;
      myFrame = app.activeDocument.pageItems.item(myCounter);
      myPage = myFrame.parent.constructor.name;
      if (myPage == “Page”)
      myPage = myFrame.parent.name;

      I can post the whole thing if it would be helpful.

      Thanks.

      Joe

    • #54064
      Joe C
      Member

      Full script:

      main();
      function main(){
      //Make certain that user interaction (display of dialogs, etc.) is turned on.
      app.scriptPreferences.userInteractionLevel = UserInteractionLevels.interactWithAll;
      if(app.documents.length != 0){
      if (app.activeDocument.stories.length != 0){
      myDisplayDialog();
      }
      else{
      alert(“The document does not contain any text. Please open a document containing text and try again.”);
      }
      }
      else{
      alert(“No documents are open. Please open a document and try again.”);
      }
      }
      var myDoc = app.documents[0];
      if (myDoc.saved == false)
      {
      alert(“Error.rYou must first save your document.”);
      exit();
      }
      var myDoc = app.documents[0];
      if (myDoc.saved == false)
      {
      alert(“Error.rYou must first save your document.”);
      exit();
      }
      function myDisplayDialog(){
      with(myDialog = app.dialogs.add({name:”ExportAllStories”})){
      //Add a dialog column.
      myDialogColumn = dialogColumns.add()
      with(myDialogColumn){
      with(borderPanels.add()){
      staticTexts.add({staticLabel:”Export as:”});
      with(myExportFormatButtons = radiobuttonGroups.add()){
      radiobuttonControls.add({staticLabel:”Text Only”, checkedState:true});
      radiobuttonControls.add({staticLabel:”RTF”});
      radiobuttonControls.add({staticLabel:”InDesign Tagged Text”});
      }
      }
      }
      myReturn = myDialog.show();
      if (myReturn == true){
      //Get the values from the dialog box.
      myExportFormat = myExportFormatButtons.selectedButton;
      myDialog.destroy;
      myFolder= Folder.selectDialog (“Choose a Folder”);
      if((myFolder != null)&&(app.activeDocument.stories.length !=0)){
      myExportAllStories(myExportFormat, myFolder);
      }
      }
      else{
      myDialog.destroy();s
      }
      }
      }
      //myExportStories function takes care of exporting the stories.
      //myExportFormat is a number from 0-2, where 0 = text only, 1 = rtf, and 3 = tagged text.
      //myFolder is a reference to the folder in which you want to save your files.
      function myExportAllStories(myExportFormat, myFolder){
      for(myCounter = 0; myCounter < app.activeDocument.stories.length; myCounter++){
      myStory = app.activeDocument.stories.item(myCounter);
      myID = myStory.id;
      myFrame = app.activeDocument.pageItems.item(myCounter);
      myPage = myFrame.parent.constructor.name;
      if (myPage == “Page”)
      myPage = myFrame.parent.name;

      switch(myExportFormat){
      case 0:
      myFormat = ExportFormat.textType;
      myExtension = “.txt”
      break;
      case 1:
      myFormat = ExportFormat.RTF;
      myExtension = “.rtf”
      break;
      case 2:
      myFormat = ExportFormat.taggedText;
      myExtension = “.txt”
      break;
      }
      myFileName =”Pg” + myPage + “StoryID” + myID + myExtension;
      myFilePath = myFolder + “/” + myFileName;
      myFile = new File(myFilePath);
      myStory.exportFile(myFormat, myFile);
      }
      }

Viewing 1 reply thread
  • You must be logged in to reply to this topic.
Forum Ads