5 Replies Latest reply on Jul 23, 2008 9:20 PM by (Olav_Kvern)

    Avoid master page stories while extracting document stories...

    dhishok Level 1
      Hi everyone,

      We have JavaScript for extracting all stories from IndesignCS2. It extracts all stories of document include master page stories also. We don't want master page stories. So please help me, how to avoid master stories in the the script.

      Thiyagu
        • 1. Re: Avoid master page stories while extracting document stories...
          Peter Kahrel Adobe Community Professional & MVP
          Show us the script, maybe someone can tell you how to change it.

          Peter
          • 2. Re: Avoid master page stories while extracting document stories...
            dhishok Level 1
            Thanks peter,

            Please find our script;

            if(app.documents.length != 0){
            if(app.documents.item(0).stories.length != 0){
            myGetFileName(app.documents.item(0).name);
            }
            }
            function myGetFileName(myDocumentName){
            var myFilePath = File.openDialog("Choose the name containing file");
            if(myFilePath != null){
            myDisplayDialog(myDocumentName, myFilePath);
            }
            }
            function myDisplayDialog(myDocumentName, myFilePath){
            //Need to get export format, story separator.
            var myExportFormats = ["RTF", "Tagged Text", "Text Only"];
            var myDialog = app.dialogs.add({name:"ExportAllStories"});
            with(myDialog.dialogColumns.add()){
            with(dialogRows.add()){
            with(dialogColumns.add()){
            var myExportFormatDropdown = dropdowns.add({stringList:myExportFormats, selectedIndex:0});
            }
            }
            with(dialogRows.add()){
            var myAddSeparatorCheckbox = checkboxControls.add({staticLabel:"Add separator line", checkedState:false});
            }
            }
            var myResult = myDialog.show();
            if(myResult == true){
            var myExportFormat = myExportFormats[myExportFormatDropdown.selectedIndex];
            var myAddSeparator = myAddSeparatorCheckbox.checkedState;
            myDialog.destroy();
            myExportAllText(myDocumentName, myFilePath, myExportFormat, myAddSeparator);
            }
            else{
            myDialog.destroy();
            }
            }
            function myExportAllText(myDocumentName, myFilePath, myExportFormat, myAddSeparator){
            var myStory;
            var myTempFolder = Folder.temp;
            var myTempFile = File(myTempFolder + "/tempTextFile.txt");
            var myNewDocument = app.documents.add();
            var myDocument = app.documents.item(myDocumentName);
            var myTextFrame = myNewDocument.pages.item(0).textFrames.add({geometricBounds:myGetBounds(myNewDocument, myNewDocument.pages.item(0))});
            var myNewStory = myTextFrame.parentStory;
            for(myCounter = 0; myCounter < myDocument.stories.length; myCounter++){
            myStory = myDocument.stories.item(myCounter);
            //Export the story as tagged text.
            myStory.exportFile(ExportFormat.taggedText, myTempFile);
            //Import (place) the file at the end of the temporary story.
            myNewStory.insertionPoints.item(-1).place(myTempFile);
            //If the imported text did not end with a return, enter a return
            //to keep the stories from running together.
            if(myCounter != myDocument.stories.length -1){
            if(myNewStory.characters.item(-1).contents != "\r"){
            myNewStory.insertionPoints.item(-1).contents = "\r";
            }
            if(myAddSeparator == true){
            myNewStory.insertionPoints.item(-1).contents = "----------------------------------------\r";
            }
            }
            }
            switch(myExportFormat){
            case "Text Only":
            myFormat = ExportFormat.textType;
            myExtension = ".txt"
            break;
            case "RTF":
            myFormat = ExportFormat.RTF;
            myExtension = ".rtf"
            break;
            case "Tagged Text":
            myFormat = ExportFormat.taggedText;
            myExtension = ".txt"
            break;
            }
            myNewStory.exportFile(myFormat, File(myFilePath));
            myNewDocument.close(SaveOptions.no);
            myTempFile.remove();
            }
            function myGetBounds(myDocument, myPage){
            var myPageWidth = myDocument.documentPreferences.pageWidth;
            var myPageHeight = myDocument.documentPreferences.pageHeight
            if(myPage.side == PageSideOptions.leftHand){
            var myX2 = myPage.marginPreferences.left;
            var myX1 = myPage.marginPreferences.right;
            }
            else{
            var myX1 = myPage.marginPreferences.left;
            var myX2 = myPage.marginPreferences.right;
            }
            var myY1 = myPage.marginPreferences.top;
            var myX2 = myPageWidth - myX2;
            var myY2 = myPageHeight - myPage.marginPreferences.bottom;
            return [myY1, myX1, myY2, myX2];
            }

            Expecting your valuable comments.

            Also this script may stopped while missing fonts dailog appeared.

            Thanks & Regards
            Thiyagu
            • 3. Re: Avoid master page stories while extracting document stories...
              Peter Kahrel Adobe Community Professional & MVP
              Aha -- this is Ole's script. What you need to do is to check for each story if it's on a master page:

              if (myStory.textFrames[0].parent.parent instanceof Spread)
              {
              //export
              }

              As to suppressing the missing-font dialog (or any other errors), use

              app.scriptPreferences.userInteractionLevel =
              UserInteractionLevels.neverInteract;

              before you export, and when the script has finished, use

              app.scriptPreferences.userInteractionLevel =
              UserInteractionLevels.interactWithAll;

              to enable dialogs again.

              Peter

              PS: when you post a script , it would help if you check what is posted to make sure that the original line breaks and indents are there. The script you posted came out as a single, unreadable, line.
              • 4. Re: Avoid master page stories while extracting document stories...
                dhishok Level 1
                Thanks Peter, you are right this is Ole's script.

                app.scriptPreferences.userInteractionLevel =
                UserInteractionLevels.neverInteract;

                If i use this for suppressing the missing-font dialog, the script dialog itself not appearing. i.e. Choosing extraction type (rtf, tagged text, xml) this gets off. And process get stopped.

                Please suggest for this.

                Thank you.
                Thiyagu
                • 5. Re: Avoid master page stories while extracting document stories...
                  Level 1
                  Hi Thiyagu,

                  You can turn user interaction back on again after the document is opened, but before you display the script dialog. That should work.

                  Thanks,

                  Ole