Skip to main content
Participating Frequently
November 27, 2013
Answered

Please provide the Story Splitter script by Adi Ravid?

  • November 27, 2013
  • 6 replies
  • 61266 views

Hi,

I'm working on a complex book and need to split threaded stories at lots of places. I know I can do it manually through the Story Editor but have really set my eyes on the Story Splitter script created by Adi Ravid. I found its place @ the Adobe Exchange (http://www.adobe.com/cfusion/exchange/index.cfm?event=extensionDetail&loc=en_us&extid=1302518#)  but get an error "We're sorry, we encountered an error processing your request." - also when pressing "Email author: Adi Ravid".

So, could someone who has the script please post it here?

Thanks a lot in advance

This topic has been closed for replies.
Correct answer Sumit_Garg

/*

------------------------------------------------------------------------------------------------------------------

StorySplitter

------------------------------------------------------------------------------------------------------------------

An InDesign CS/CS2/CS3 JavaScript by FourAces

© The Final Touch 2006

Version 3.0.0

Splits the selected Story to separate Text Frames, while maintaining their contents.

------------------------------------------------------------------------------------------------------------------

*/

var myScriptVer = "3.0";

if(app.documents.length != 0){

          var mySelection = app.activeDocument.selection;

          if(mySelection.length != 0){

                    myObjectType = mySelection[0].constructor.name;

                    if(myObjectType == "TextFrame"){

                              //The Interface Dialog

                              var myDialog = app.dialogs.add({name:"Story Splitter v"+ myScriptVer});

                              with(myDialog){

                                        with(dialogColumns.add()){

                                                  with (dialogRows.add()){

                                                            with(borderPanels.add()){

                                                                      var mySplitOptions = radiobuttonGroups.add();

                                                                      with(mySplitOptions){

                                                                                radiobuttonControls.add({staticLabel:"Split All Frames", checkedState:true});

                                                                                radiobuttonControls.add({staticLabel:"Split Before Selected Frame"});

                                                                                radiobuttonControls.add({staticLabel:"Split After Selected Frame"});

                                                                      }

                                                            }

                                                  }

                                                  with (dialogRows.add()){

                                                            staticTexts.add({staticLabel:"© The Final Touch"});

                                                  }

                                        }

                              }

                              var myResult = myDialog.show({name:"SplitOptions"});

                              if(myResult == true){

                                        var myStory = mySelection[0].parentStory;

                                        if(app.version.split(".")[0] >= 5){

                                                  var myTextFrames = myStory.textContainers;

                                        }

                                        else{

                                                  var myTextFrames = myStory.textFrames;

                                        }

                                        var myStoryFramesCount = myTextFrames.length;

                                        if(myStoryFramesCount > 1){

                                                  for(f = 0; f < myStoryFramesCount; f++){

                                                            if (mySelection[0] == myStory.textFrames){

                                                                      var myTextFrame = f;

                                                            }

                                                  }

                                                  switch(mySplitOptions.selectedButton){

                                                            case 0:

                                                                      mySplitAll();

                                                                      break;

                                                            case 1:

                                                                      mySplitBefore();

                                                                      break;

                                                            case 2:

                                                                      mySplitAfter();

                                                                      break;

                                                  }

                                        }

                                        else{

                                                  alert("Are You Kidding Me?!\nThe Story you selected has only ONE text frame.");

                                        }

                              }

                    }

                    else{

                              alert("Wrong Selection\nYou selected the wrong type of object. Please select a Text Frame.");

                    }

          }

          else{

                    alert("No Selection Made.\nPlease select a Story to split.");

          }

}

else{

          alert("No Active Document Found.\nPlease open an InDesign document and select a Story to split.");

}

//----------------------------------------------------------------------------

function mySplitAll(){

          for(i = 0; i < myStoryFramesCount; i++){

                    myTextFrames.duplicate();

          }

          for(i = 0; i < myStoryFramesCount; i++){

                    if(app.version.split(".")[0] >= 5){

                              myTextFrames.remove();

                    }

                    else{

                              myTextFrames[0].remove();

                    }

          }

}

function mySplitBefore(){

          if(mySelection[0].previousTextFrame == null){

                    alert("Unable Break Thread.\nThe selected Text Frame is the FIRST text frame of the thread.");

          }

          else{

                    var myBfBreakFrame = mySelection[0].previousTextFrame;

                    var myAfBreakFrame = mySelection[0];

                    var myBreakStory = myBfBreakFrame.parentStory;

                    mySelection[0].previousTextFrame = null;

                    if(myBfBreakFrame.overflows == true){

                              var myOversetText = myBreakStory.texts.itemByRange(myBfBreakFrame.insertionPoints[-1],myBreakStory.insertionPoints[-1]);

                              myOversetText.select();

                              app.cut();

                              app.select(myAfBreakFrame.insertionPoints[0]);

                              app.paste();

                    }

          }

}

function mySplitAfter(){

          if(mySelection[0].nextTextFrame == null){

                    alert("Unable Break Thread.\nThe selected Text Frame is the LAST text frame of the thread.");

          }

          else{

                    var myBfBreakFrame = mySelection[0];

                    var myAfBreakFrame = mySelection[0].nextTextFrame;

                    var myBreakStory = myBfBreakFrame.parentStory;

                    mySelection[0]          .nextTextFrame = null;

                    if(myBfBreakFrame.overflows == true){

                                        var myOversetText = myBreakStory.texts.itemByRange(myBfBreakFrame.insertionPoints[-1],myBreakStory.insertionPoints[-1]);

                              myOversetText.select();

                              app.cut();

                              app.select(myAfBreakFrame.insertionPoints[0]);

                              app.paste();

 

                    }

          }

}

6 replies

Community Expert
December 15, 2020

Hi Brian,

if you have InDesign 2020 version 15.1 or InDesign 2021 installed, you have access to the pre-installed script BreakTextThread.jsx by Timothy Arial Walden through the Scripts panel's Community folder.

That's a good substitute for the Story Splitter script.

 

Hope your company security gives you access to this page where the author goes into detail:

 

Break Text Thread: A Free InDesign Script
by Ariel, January 28, 2020
https://www.id-extras.com/break-text-thread/

 

Regards,
Uwe Laubender

( ACP )

Community Expert
December 30, 2019

Maybe it's better to post the link to the script's code:

https://github.com/jalberts/StorySplitter/blob/master/StorySplitter.jsx

 

FWIW: Just tested the code with InDesign 2020 on Windows 10.

No issues so far.

 

Regards,
Uwe Laubender

( ACP )

Participating Frequently
December 15, 2020

Our new corporate security won't allow access much online content including the link you kindly provided (I think it's only going to get harder to find and share answers).

Community Expert
December 22, 2019

Hi schroef,

the error with

myTextFrames.duplicate();

vs

myTextFrames[i].duplicate();

 

is because of a faulty transfer of the old threads to the new forum software.

Happend to my old posted code as well. That's a disaster!

 

Thank you for repairing the script code.

 

Regards,
Uwe Laubender

( ACP )

 

schroef
Inspiring
December 23, 2019

Yeah this new community design wrecked a lot of things. I also see many deadlinks now in posts linked from stack exchange or other forums.

 

What is weird though that the [0] version are there and it only took out [i]????

Sleem
Participant
October 17, 2017

Here is the final script, open notepad, paste the code, save as StorySplitter.jsx

/*

---------------------------------------------------------------------- --------------------------------------------

StorySplitter

---------------------------------------------------------------------- --------------------------------------------

An InDesign CS/CS2/CS3 JavaScript by FourAces

© The Final Touch 2006

Version 3.0.0

Splits the selected Story to separate Text Frames, while maintaining their contents.

---------------------------------------------------------------------- --------------------------------------------

*/

var myScriptVer = "3.0";

if(app.documents.length != 0){

          var mySelection = app.activeDocument.selection;

          if(mySelection.length != 0){

                    myObjectType = mySelection[0].constructor.name;

                    if(myObjectType == "TextFrame"){

                              //The Interface Dialog

                              var myDialog = app.dialogs.add({name:"Story Splitter v"+ myScriptVer});

                              with(myDialog){

                                        with(dialogColumns.add()){

                                                  with (dialogRows.add()){

                                                            with(borderPanels.add()){

                                                                      var mySplitOptions = radiobuttonGroups.add();

                                                                      with(mySplitOptions){

                                                                                radiobuttonControls.add({staticLabel:"Split All Frames", checkedState:true});

                                                                                radiobuttonControls.add({staticLabel:"Split Before Selected Frame"});

                                                                                radiobuttonControls.add({staticLabel:"Split After Selected Frame"});

                                                                      }

                                                            }

                                                  }

                                                  with (dialogRows.add()){

                                                            staticTexts.add({staticLabel:"© The Final Touch"});

                                                  }

                                        }

                              }

                              var myResult = myDialog.show({name:"SplitOptions"});

                              if(myResult == true){

                                        var myStory = mySelection[0].parentStory;

                                        if(app.version.split(".")[0] >= 5){

                                                  var myTextFrames = myStory.textContainers;

                                        }

                                        else{

                                                  var myTextFrames = myStory.textFrames;

                                        }

                                        var myStoryFramesCount = myTextFrames.length;

                                        if(myStoryFramesCount > 1){

                                                  for(f = 0; f < myStoryFramesCount; f++){

                                                            if (mySelection[0] == myStory.textFrames){

                                                                      var myTextFrame = f;

                                                            }

                                                  }

                                                  switch(mySplitOptions.selectedButton){

                                                            case 0:

                                                                      mySplitAll();

                                                                      break;

                                                            case 1:

                                                                      mySplitBefore();

                                                                      break;

                                                            case 2:

                                                                      mySplitAfter();

                                                                      break;

                                                  }

                                        }

                                        else{

                                                  alert("Are You Kidding Me?!\nThe Story you selected has only ONE text frame.");

                                        }

                              }

                    }

                    else{

                              alert("Wrong Selection\nYou selected the wrong type of object. Please select a Text Frame.");

                    }

          }

          else{

                    alert("No Selection Made.\nPlease select a Story to split.");

          }

}

else{

          alert("No Active Document Found.\nPlease open an InDesign document and select a Story to split.");

}

//-------------------------------------------------------------------- --------

function mySplitAll(){

          for(i = 0; i < myStoryFramesCount; i++){

                    myTextFrames.duplicate();

          }

          for(i = 0; i < myStoryFramesCount; i++){

                    if(app.version.split(".")[0] >= 5){

                              myTextFrames.remove();

                    }

                    else{

                              myTextFrames[0].remove();

                    }

          }

}

function mySplitBefore(){

          if(mySelection[0].previousTextFrame == null){

                    alert("Unable to break thread.\nThe selected Text Frame is the FIRST text frame of the thread.");

          }

          else{

                    var myBfBreakFrame = mySelection[0].previousTextFrame;

                    var myAfBreakFrame = mySelection[0];

                    var myBreakStory = myBfBreakFrame.parentStory;

                    mySelection[0].previousTextFrame = null;

                    if(myBfBreakFrame.overflows == true){

                              var myOversetText = myBreakStory.texts.itemByRange(myBfBreakFrame.insertionPoints[-1],myBreakStory.insertionPoints[-1]);

                              myOversetText.select();

                              app.cut();

                              app.select(myAfBreakFrame.insertionPoints[0]);

                              app.paste();

                    }

          }

}

function mySplitAfter(){

          if(mySelection[0].nextTextFrame == null){

                    alert("Unable Break Thread.\nThe selected Text Frame is the LAST text frame of the thread.");

          }

          else{

                    var myBfBreakFrame = mySelection[0];

                    var myAfBreakFrame = mySelection[0].nextTextFrame;

                    var myBreakStory = myBfBreakFrame.parentStory;

                    mySelection[0].nextTextFrame = null;

                    if(myBfBreakFrame.overflows == true){

                              var myOversetText = myBreakStory.texts.itemByRange(myBfBreakFrame.insertionPoints[-1],myBreakStory.insertionPoints[-1]);

                              myOversetText.select();

                              app.cut();

                              app.select(myAfBreakFrame.insertionPoints[0]);

                              app.paste();

                    }

          }

}

schroef
Inspiring
December 20, 2019

@Sleem,

 

im getting an error in indesign 2018cc

 

It returns an error for the line 166 > myTextFrames.duplicate(); says its not a functions, error number 24
I see the variable is declared in a different function though?

schroef
Inspiring
December 20, 2019

Okay i got it fixed now by change line 165 and line 172. I noticed it was looping of the FrameCount but was trying to duplicate a total number. I added [i] and now all frame get split.

Here's my adjusted version, i bumped it to 3.0.1 now

 

/*
---------------------------------------------------------------------- --------------------------------------------
StorySplitter
---------------------------------------------------------------------- --------------------------------------------
An InDesign CS/CS2/CS3 JavaScript by FourAces
© The Final Touch 2006
Version 3.0.0
Splits the selected Story to separate Text Frames, while maintaining their contents.
---------------------------------------------------------------------- --------------------------------------------
See https://community.adobe.com/t5/indesign/please-provide-the-story-splitter-script-by-adi-ravid/td-p/5657620
Fixed #165 > changed myTextFrames.duplicate(); to myTextFrames[i].duplicate(); as well as on #172
V 3.0.1 - 20-12-2019
*/

var myScriptVer = "3.0.1";
if (app.documents.length != 0) {
    var mySelection = app.activeDocument.selection;
    if (mySelection.length != 0) {
        myObjectType = mySelection[0].constructor.name;
        if (myObjectType == "TextFrame") {
            //The Interface Dialog
            var myDialog = app.dialogs.add({
                name: "Story Splitter v" + myScriptVer
            });
            with (myDialog) {
                with (dialogColumns.add()) {
                    with (dialogRows.add()) {
                        with (borderPanels.add()) {
                            var mySplitOptions = radiobuttonGroups.add();
                            with (mySplitOptions) {
                                radiobuttonControls.add({
                                    staticLabel: "Split All Frames",
                                    checkedState: true
                                });
                                radiobuttonControls.add({
                                    staticLabel: "Split Before Selected Frame"
                                });
                                radiobuttonControls.add({
                                    staticLabel: "Split After Selected Frame"
                                });
                            }
                        }
                    }
                    with (dialogRows.add()) {
                        staticTexts.add({
                            staticLabel: "© The Final Touch"
                        });
                    }
                }
            }
            var myResult = myDialog.show({
                name: "SplitOptions"
            });
            if (myResult == true) {
                var myStory = mySelection[0].parentStory;
                if (app.version.split(".")[0] >= 5) {
                    var myTextFrames = myStory.textContainers;
                } else {
                    var myTextFrames = myStory.textFrames;
                }
                var myStoryFramesCount = myTextFrames.length;
                if (myStoryFramesCount > 1) {
                    for (f = 0; f < myStoryFramesCount; f++) {
                        if (mySelection[0] == myTextFrames) {
                            var myTextFrame = f;
                        }
                    }
                    // alert(mySelection[0]);
                    switch (mySplitOptions.selectedButton) {
                        case 0:
                            mySplitAll();
                            break;
                        case 1:
                            mySplitBefore();
                            break;
                        case 2:
                            mySplitAfter();
                            break;
                    }
                } else {
                    alert("Are You Kidding Me?!\nThe Story you selected has only ONE text frame.");
                }
            }
        } else {
            alert("Wrong Selection\nYou selected the wrong type of object. Please select a Text Frame.");
        }
    } else {
        alert("No Selection Made.\nPlease select a Story to split.");
    }
} else {
    alert("No Active Document Found.\nPlease open an InDesign document and select a Story to split.");
}

//-------------------------------------------------------------------- --------
function mySplitAll() {
    for (i = 0; i < myStoryFramesCount; i++) {
        myTextFrames[i].duplicate();
    }
    for (i = 0; i < myStoryFramesCount; i++) {
        if (app.version.split(".")[0] >= 5) {
            myTextFrames[i].remove();
        } else {
            myTextFrames[0].remove();
        }
    }
}

function mySplitBefore() {
    if (mySelection[0].previousTextFrame == null) {
        alert("Unable to break thread.\nThe selected Text Frame is the FIRST text frame of the thread.");
    } else {
        var myBfBreakFrame = mySelection[0].previousTextFrame;
        var myAfBreakFrame = mySelection[0];
        var myBreakStory = myBfBreakFrame.parentStory;
        mySelection[0].previousTextFrame = null;
        if (myBfBreakFrame.overflows == true) {
            var myOversetText = myBreakStory.texts.itemByRange(myBfBreakFrame.insertionPoints[-1], myBreakStory.insertionPoints[-1]);
            myOversetText.select();
            app.cut();
            app.select(myAfBreakFrame.insertionPoints[0]);
            app.paste();
        }
    }
}

function mySplitAfter() {
    if (mySelection[0].nextTextFrame == null) {
        alert("Unable Break Thread.\nThe selected Text Frame is the LAST text frame of the thread.");
    } else {
        var myBfBreakFrame = mySelection[0];
        var myAfBreakFrame = mySelection[0].nextTextFrame;
        var myBreakStory = myBfBreakFrame.parentStory;
        mySelection[0].nextTextFrame = null;
        if (myBfBreakFrame.overflows == true) {
            var myOversetText = myBreakStory.texts.itemByRange(myBfBreakFrame.insertionPoints[-1], myBreakStory.insertionPoints[-1]);
            myOversetText.select();
            app.cut();
            app.select(myAfBreakFrame.insertionPoints[0]);
            app.paste();
        }
    }
}
JaxiterAuthor
Participating Frequently
November 27, 2013

Thanks a lot for posting the script!

However, it gives the following error, as it appears when creating the dialog box:

---------------------------

Adobe InDesign

---------------------------

JavaScript Error!

Error Number: 25

Error String: Expected: :

Engine: main

File: C:\Users\MYPC\AppData\Roaming\Adobe\InDesign\Version 8.0-ME\en_AE\Scripts\Scripts Panel\StorySplitter.js

Line: 29

Source: radiobuttonControls.add({stat icLabel:"Split All Frames", checkedState:true});

Offending Text: icLabel

Someone who could help me out please?

Jump_Over
Legend
November 27, 2013

Hi,

Copy...paste source code more accurate (watch spaces at line ends):

i.e.

radiobuttonControls.add({stat icLabel:"Split All Frames", checkedState:true});

suppose to be:

radiobuttonControls.add({staticLabel:"Split All Frames", checkedState:true});

Jarek

JaxiterAuthor
Participating Frequently
November 27, 2013

Hi Jump_Over,

Hmm indeed, thanks for spotting that Nnow that I look at the code above there seem to be more spaces breaking up things - I'll try to find and remove them.

Thanks again

Sumit_Garg
Adobe Employee
Sumit_GargCorrect answer
Adobe Employee
November 27, 2013

/*

------------------------------------------------------------------------------------------------------------------

StorySplitter

------------------------------------------------------------------------------------------------------------------

An InDesign CS/CS2/CS3 JavaScript by FourAces

© The Final Touch 2006

Version 3.0.0

Splits the selected Story to separate Text Frames, while maintaining their contents.

------------------------------------------------------------------------------------------------------------------

*/

var myScriptVer = "3.0";

if(app.documents.length != 0){

          var mySelection = app.activeDocument.selection;

          if(mySelection.length != 0){

                    myObjectType = mySelection[0].constructor.name;

                    if(myObjectType == "TextFrame"){

                              //The Interface Dialog

                              var myDialog = app.dialogs.add({name:"Story Splitter v"+ myScriptVer});

                              with(myDialog){

                                        with(dialogColumns.add()){

                                                  with (dialogRows.add()){

                                                            with(borderPanels.add()){

                                                                      var mySplitOptions = radiobuttonGroups.add();

                                                                      with(mySplitOptions){

                                                                                radiobuttonControls.add({staticLabel:"Split All Frames", checkedState:true});

                                                                                radiobuttonControls.add({staticLabel:"Split Before Selected Frame"});

                                                                                radiobuttonControls.add({staticLabel:"Split After Selected Frame"});

                                                                      }

                                                            }

                                                  }

                                                  with (dialogRows.add()){

                                                            staticTexts.add({staticLabel:"© The Final Touch"});

                                                  }

                                        }

                              }

                              var myResult = myDialog.show({name:"SplitOptions"});

                              if(myResult == true){

                                        var myStory = mySelection[0].parentStory;

                                        if(app.version.split(".")[0] >= 5){

                                                  var myTextFrames = myStory.textContainers;

                                        }

                                        else{

                                                  var myTextFrames = myStory.textFrames;

                                        }

                                        var myStoryFramesCount = myTextFrames.length;

                                        if(myStoryFramesCount > 1){

                                                  for(f = 0; f < myStoryFramesCount; f++){

                                                            if (mySelection[0] == myStory.textFrames){

                                                                      var myTextFrame = f;

                                                            }

                                                  }

                                                  switch(mySplitOptions.selectedButton){

                                                            case 0:

                                                                      mySplitAll();

                                                                      break;

                                                            case 1:

                                                                      mySplitBefore();

                                                                      break;

                                                            case 2:

                                                                      mySplitAfter();

                                                                      break;

                                                  }

                                        }

                                        else{

                                                  alert("Are You Kidding Me?!\nThe Story you selected has only ONE text frame.");

                                        }

                              }

                    }

                    else{

                              alert("Wrong Selection\nYou selected the wrong type of object. Please select a Text Frame.");

                    }

          }

          else{

                    alert("No Selection Made.\nPlease select a Story to split.");

          }

}

else{

          alert("No Active Document Found.\nPlease open an InDesign document and select a Story to split.");

}

//----------------------------------------------------------------------------

function mySplitAll(){

          for(i = 0; i < myStoryFramesCount; i++){

                    myTextFrames.duplicate();

          }

          for(i = 0; i < myStoryFramesCount; i++){

                    if(app.version.split(".")[0] >= 5){

                              myTextFrames.remove();

                    }

                    else{

                              myTextFrames[0].remove();

                    }

          }

}

function mySplitBefore(){

          if(mySelection[0].previousTextFrame == null){

                    alert("Unable Break Thread.\nThe selected Text Frame is the FIRST text frame of the thread.");

          }

          else{

                    var myBfBreakFrame = mySelection[0].previousTextFrame;

                    var myAfBreakFrame = mySelection[0];

                    var myBreakStory = myBfBreakFrame.parentStory;

                    mySelection[0].previousTextFrame = null;

                    if(myBfBreakFrame.overflows == true){

                              var myOversetText = myBreakStory.texts.itemByRange(myBfBreakFrame.insertionPoints[-1],myBreakStory.insertionPoints[-1]);

                              myOversetText.select();

                              app.cut();

                              app.select(myAfBreakFrame.insertionPoints[0]);

                              app.paste();

                    }

          }

}

function mySplitAfter(){

          if(mySelection[0].nextTextFrame == null){

                    alert("Unable Break Thread.\nThe selected Text Frame is the LAST text frame of the thread.");

          }

          else{

                    var myBfBreakFrame = mySelection[0];

                    var myAfBreakFrame = mySelection[0].nextTextFrame;

                    var myBreakStory = myBfBreakFrame.parentStory;

                    mySelection[0]          .nextTextFrame = null;

                    if(myBfBreakFrame.overflows == true){

                                        var myOversetText = myBreakStory.texts.itemByRange(myBfBreakFrame.insertionPoints[-1],myBreakStory.insertionPoints[-1]);

                              myOversetText.select();

                              app.cut();

                              app.select(myAfBreakFrame.insertionPoints[0]);

                              app.paste();

 

                    }

          }

}