Skip to main content
Inspiring
July 14, 2014
Answered

Rethread all text frames by current page order

  • July 14, 2014
  • 1 reply
  • 932 views

Hello

I made a 'mistake' today, wondering if there is anything to do about it

  • I have an InDi file with 1 story - multi chapter
  • every page is a new chapter (small chapters)
  • I wanted to change the order, so I moved the pages! (not the text)
  • Now, when I am on page 12, if I add text, or press the down arrow, it is going into page 3! etc.

Is there a way to rethread all text frames?

I.e., break the current threading, and then rethread each page's frame to the next?

Any help and guidance will be appreciated

Thanks

Davey

This topic has been closed for replies.
Correct answer Kai Rübsamen

Yeap,

The problem is only you can see how it appears. I can just read what you wrote, nothing else.

You shouldn't ask for "re-threading" frames if your goal is to recompose text. There are different stories.

I gave you a code to step back from a mistake you wrote about.

To reach a goal with recomposing I suggest workflow like:

  • duplicate a doc
  • remove main story
  • link frames as page order
  • duplicate particular texts page by page from original doc to a copy

Assuming 3 steps are done - 4th depends on your doc structure (how many frames on page, how to detect a proper textFrame, is it named?)

Lets assume you did an empty copy with textFrame linked in page order and there is only one frame per page and a story starts from 1st page.

Keep source and output opened and activate a source. Then run this:

var

  sourceDoc = app.activeDocument,

  outputDoc = app.documents[1],

  myTextArray = sourceDoc.pages.everyItem().textFrames.everyItem().texts.everyItem().getElements();

for (var k=0; k<myTextArray.length; k++)

  myTextArray.duplicate(LocationOptions.AFTER, outputDoc.pages[0].textFrames[0].parentStory.texts[0] );

Jarek


I’m not sure, if I understand the goal correctly and we talk about the same things if we talk about recomposing or re-threading.

I would do the following:

1. Use Adobes script split story. This will duplicate all Frames and delete the origin story

2. Re-Thread the frames in the order as shown on the document pages

3. To prevent any other frames on the page, give the frames before re-threading or recomposing ;-) a name

// check selection

if ( !( app.selection.length == 1 && ( app.selection[0].hasOwnProperty('baseline') || app.selection[0].constructor.name == "TextFrame" ) )) {

    alert( "wrong selection!" );

    exit();

}

var curStory = app.selection[0].parentStory;

var curDoc = app.activeDocument;

if ( curStory.textContainers.length > 1 ) {

    mySplitStory( curStory );

    myRemoveFrames( curStory );

}

relinkTextFrames ( curDoc.textFrames );

               

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.name = "linkme";

        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();

    }

}

function relinkTextFrames( myTextFrames ) {

    var collectTFrames = [];

    for (var i = 0; i < myTextFrames.length; i++ ) {

        if ( myTextFrames.name == "linkme" ) {

            collectTFrames.push(myTextFrames);

        }

    }

    for ( var n = 0; n < collectTFrames.length-1; n++ ) {

        var curTFrame = collectTFrames;

        var nextTFrame = collectTFrames[n+1];

        curTFrame.nextTextFrame = nextTFrame;

    }

}

1 reply

Jump_Over
Legend
July 14, 2014

Hi,

Backup your doc and run this:

(one of threated textFrames supposed to be selected)

var

  mFrames = app.selection[0].parentStory.textContainers,

  len = mFrames.length,

  cTxtReflowSet = app.activeDocument.textPreferences.smartTextReflow;

app.activeDocument.textPreferences.smartTextReflow = false;

while (len-->0) {

  mFrames[len].nextTextFrame = null;

  }

mFrames.sort(sortByPage);

len = mFrames.length;

while (len-->1)

  mFrames[len].previousTextFrame = mFrames[len-1];

app.activeDocument.textPreferences.smartTextReflow = cTxtReflowSet;

function sortByPage (a,b) {

  return a.parentPage.documentOffset > b.parentPage.documentOffset;

  }

Jarek

myDaveyAuthor
Inspiring
July 14, 2014

Hi Jarek

Thanks a lot for your response

I dont think this is working properly

It seems to me that it is putting it back to the order in which it was originally

Instead, I wanted to thread the text as it appears in the current page order

Thanks

Davey

Jump_Over
Legend
July 14, 2014

Yeap,

The problem is only you can see how it appears. I can just read what you wrote, nothing else.

You shouldn't ask for "re-threading" frames if your goal is to recompose text. There are different stories.

I gave you a code to step back from a mistake you wrote about.

To reach a goal with recomposing I suggest workflow like:

  • duplicate a doc
  • remove main story
  • link frames as page order
  • duplicate particular texts page by page from original doc to a copy

Assuming 3 steps are done - 4th depends on your doc structure (how many frames on page, how to detect a proper textFrame, is it named?)

Lets assume you did an empty copy with textFrame linked in page order and there is only one frame per page and a story starts from 1st page.

Keep source and output opened and activate a source. Then run this:

var

  sourceDoc = app.activeDocument,

  outputDoc = app.documents[1],

  myTextArray = sourceDoc.pages.everyItem().textFrames.everyItem().texts.everyItem().getElements();

for (var k=0; k<myTextArray.length; k++)

  myTextArray.duplicate(LocationOptions.AFTER, outputDoc.pages[0].textFrames[0].parentStory.texts[0] );

Jarek