Skip to content

Commit

Permalink
Add headless story splitter
Browse files Browse the repository at this point in the history
  • Loading branch information
Bruno Herfst committed Jul 25, 2018
1 parent e8b3449 commit 7e7ac1e
Show file tree
Hide file tree
Showing 2 changed files with 97 additions and 10 deletions.
14 changes: 4 additions & 10 deletions Scripts/Frame_Splits_Story_UI.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,23 +13,17 @@ Splits the selected Story to separate Text Frames, while maintaining their conte
// Adjusted by Bruno Herfst to suit needs
// 1. Return to selected frame page
// Don't have time for this now but it would be good if there was an option for style based splitting.
// Will proberbly have to write from scratch to avoid the App.c

#target indesign;

var myScriptVer = "3.0";

function mySplitAll() {
for(i = 0; i < myStoryFramesCount; i++){
myTextFrames[i].duplicate();
for(var 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();
}
for(var i = 0; i < myStoryFramesCount; i++){
myTextFrames[i].remove();
}
}

Expand Down
93 changes: 93 additions & 0 deletions Scripts/Story_Splitter.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
/*
Story_Splitter.jsx
Headless story splitter based on StorySplitter by FourAces
With selection: Splits all stories found in selection
Without selection: Splits all stories in active document
----------------------------------------------------------------------
StorySplitter
----------------------------------------------------------------------
An InDesign CS/CS2/CS3 JavaScript by FourAces
© The Final Touch 2006
Version 3.0
Splits the selected Story to separate Text Frames, while maintaining their contents.
----------------------------------------------------------------------
*/

#target indesign;

function mySplitAll( tFrames ) {
var len = tFrames.length;
alert(len);
if (len === 1) return;
for(var i = 0; i < len; i++){
tFrames[i].duplicate();
};
for(var i = 0; i < len; i++){
tFrames[i].remove();
};
};

function splitStories( storyArr ) {
for(var i = 0; i < storyArr.length; i++) {
var myStory = storyArr[i];
if(app.version.split(".")[0] >= 5){
var tFrames = myStory.textContainers;
} else {
var tFrames = myStory.textFrames;
};
mySplitAll( tFrames );
};
};

function notInArray(needle, array) {
for(var i = 0; i < array.length; i++) {
if(array[i] === needle) {
return false;
}
}
return true;
};

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

if(app.documents.length != 0){
var mySelection = app.activeDocument.selection;
var selected_stories = [];
if( mySelection.length === 0){
// Do all stories
for(var i = 0; i < app.activeDocument.stories.length; i++){
selected_stories.push(app.activeDocument.stories.item(i));
};
} else {
// Do stories in selection
for(var i = 0; i < mySelection.length; i++){
switch(mySelection[i].constructor.name){
//we can add insertion points paragraphs too just look them up
case "TextFrame":
case "Paragraph":
case "Text":
case "Line":
case "Word":
case "Character":
case "TextColumn":
case "TextStyleRange":
var myStory = mySelection[i].parentStory;
if(notInArray(myStory, selected_stories)){
selected_stories.push(myStory);
};
break;
default:
break;
};
};
};
splitStories(selected_stories);
alert("Done");
} else {
alert("No Active Document Found.\nPlease open an InDesign document and select a Story to split.");
} // EOF

0 comments on commit 7e7ac1e

Please sign in to comment.