Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
2

Re-linking text frames after splitting with a script

Community Beginner ,
Jul 21, 2023 Jul 21, 2023

I used a script to split the chapters in my book, but I see that some have been split one frame too late. How can I re-link these text frames so the chapters are once again whole?

TOPICS
Scripting
385
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct answer

Community Expert , Jul 22, 2023 Jul 22, 2023

Just copy the code and paste into a plain text editor. Save as StorySplitter.jsx and install.

How to install scripts in InDesign | CreativePro Network

Translate
Community Expert ,
Jul 21, 2023 Jul 21, 2023

Are you still in a single document, or are the chapters individual files?

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Jul 21, 2023 Jul 21, 2023

Still in a single document

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Jul 22, 2023 Jul 22, 2023

Relink the incorrect splits manually then spliot again at the correct frame. Not sure what script you were using, but the BreakFrame.jsx sample script included with the program will divide the story at the end of the frame you have selected when you run it.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Jul 22, 2023 Jul 22, 2023

Sorry, wrong script. Hang on a minute....

 

/*
------------------------------------------------------------------------------------------------------------------
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[f]){
							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[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 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();
		
		}
	}
}

Just tested and this still runs in version 18. Options to break sttory into individual indepemdent frames or divide making selected frame first or last in story.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Jul 22, 2023 Jul 22, 2023

Thanks for this, I'm new to scripting. How do I create a script file using this code?

 

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Jul 22, 2023 Jul 22, 2023

Just copy the code and paste into a plain text editor. Save as StorySplitter.jsx and install.

How to install scripts in InDesign | CreativePro Network

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Jul 29, 2023 Jul 29, 2023

Great thanks so much for your help!

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Jul 29, 2023 Jul 29, 2023

My pleasure.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Jul 30, 2023 Jul 30, 2023

Am I missing something ??

 

OP wanted to RE-Link splitted TextFrames - but your script is still only splitting ?

Just asking.

 

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Jul 30, 2023 Jul 30, 2023

Yes. The first part was to manually relink the incorrect splits. After that he can run the script and have good control over where the split happens.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Jul 30, 2023 Jul 30, 2023

That's what I thought. 

It doesn't re-link them - it just split them better. 

 

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Jul 30, 2023 Jul 30, 2023
LATEST

Yes, I should have clarified that it was actually the relinking part that my brain was struggling with. To be honest I should have known how to do this manually!

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines