2 Replies Latest reply on May 7, 2012 5:59 PM by Austinkir

    SplitStory to all, not just selected

    arktype1

      Hello, I'm trying to modify SplitStory.jsx to split everything that is linked everywhere in the document in one pass.

       

      Below is what I've come up with, but am having a hard time getting it to work:

      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){
                                    var myThreadedText = app.activeDocument.stories.everyItem().textContainers;
                                    switch(myThreadedText.constructor.name){
                                              case "Text":
                                              case "InsertionPoint":
                                              case "Character":
                                              case "Word":
                                              case "Line":
                                              case "TextStyleRange":
                                              case "Paragraph":
                                              case "TextColumn":
                                              case "TextFrame":
                                                        if(myThreadedText.parentStory.textContainers.length > 1){
                                                                  mySplitStory(myThreadedText.parentStory);
                                                                  myRemoveFrames(myThreadedText.parentStory);
                                                        }
                                                        else{
                                                                  alert("Please make sure there  are threaded text-frames.");
                                                        }
                                                        break;
                                              default:
                                                        alert("Error. Try running SplitStory instead on each instance.");
                                    }
                }
                else{
                          alert("Please open a document and try again.");
                }
      }
      function mySplitStory(myStory){
                var myTextFrame;
                //Duplicate each text frame in the story.
                for(var myCounter = myStory.textContainers.length-1; myCounter >= 0; myCounter --){
                          myTextFrame = myStory.textContainers[myCounter];
                          myTextFrame.duplicate();
                }
      }
      function myRemoveFrames(myStory){
                //Remove each text frame in the story. Iterate backwards to avoid invalid references.
                for(var myCounter = myStory.textContainers.length-1; myCounter >= 0; myCounter --){
                          myStory.textContainers[myCounter].remove();
                }
      }
      
      

       

      Is what I'm trying to do even possible?

       

      The reason I'm doing this is I'm exporting documents as IDML and then using a custom tool to parse through them and get at what I need for my application. It's much harder however to set up the tool to handle threaded text-boxes, so for now I'm just splitting them all. In a 500 page document, this can take a bit of time and is frusturating when I miss something by mistake.

        • 1. Re: SplitStory to all, not just selected
          John Hawkinson Level 5

          You'll need to use a loop.

          Read up on for loops.

           

          But this construction couldn't possibly work:

           

          var myThreadedText = app.activeDocument.stories.everyItem().textContainers;
                                        switch(myThreadedText.constructor.name){

          In this case, myThreadedText is a plural object, effectively an array of all the textContainers of all the stories.

          But on the next line, and in subsequent statements, you treat it like it is an individual single story.

           

          Also: why is one pass important?

          • 2. Re: SplitStory to all, not just selected
            Austinkir

            Hello, I know this thread is old (I thought I responded to this by email, but I guess that just went to John). I still have the same problem. I want to do it all in one pass because I'm working with books that are sometimes 500 pages long, and it makes it much easier for me if I can have no stories.

             

            I did some reading on for loops and came up with this, but I think I'm missing something:

            //SplitStoryALL.jsx

            //

             

             

            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){

                                var myDoc = app.activeDocument;

                                var myStories = 0;

                                for (var i = 0; myDoc.stories.length > i; i++)

                                    myStories = myDoc.stories[i];

                                          mySplitStory(myStories);

                                          myRemoveFrames(myStories);

                      }

                      else{

                                alert("Please open a document and try again.");

                      }

            }

            function mySplitStory(myStory){

                      var myTextFrame;

                      //Duplicate each text frame in the story.

                      for(var myCounter = myStory.textContainers.length-1; myCounter >= 0; myCounter --){

                                myTextFrame = myStory.textContainers[myCounter];

                                myTextFrame.duplicate();

                      }

            }

            function myRemoveFrames(myStory){

                      //Remove each text frame in the story. Iterate backwards to avoid invalid references.

                      for(var myCounter = myStory.textContainers.length-1; myCounter >= 0; myCounter --){

                                myStory.textContainers[myCounter].remove();

                      }

            }

             

            I'm super new to scripting, any help pointing me in the right direction would be much appriciated.