Skip to main content
Participant
February 12, 2014
Answered

How to alphabetical order pages at indesign cs4?

  • February 12, 2014
  • 1 reply
  • 4232 views

I have a text box at the beginning of each page and I want to alphabetical order pages based on that text box. Do you know how to do that?

This topic has been closed for replies.
Correct answer Trevor:

This will do it.

But see also http://forums.adobe.com/thread/1082984?tstart=0 for a better workflow.

For some reason the OP over there didn't get back to say thanks and mark the answer as correct .

Trevor

// Script to sort Pages according to alphabetical order of their top TextFrames contents

// by Trevor (www.creative-scripts.com [coming soon]) custom and readymade scripts for InDesign

// http://forums.adobe.com/thread/1405293?tstart=0

// see also http://forums.adobe.com/thread/1082984?tstart=0 for a better workflow

app.doScript("aToZPageSort()", ScriptLanguage.javascript, undefined, UndoModes.FAST_ENTIRE_SCRIPT, "Sort Pages By top text contents");

function aToZPageSort () {

    var doc =  app.documents[0],

          myPageIndex = [],

          l = doc.pages.length,

          topFrameIndex = z= 0, pageFramesTops, i, topFrameHeight, topFrame;

    while (l--) {

        pageFramesTops = doc.pages.textFrames.everyItem().getElements().slice(0);

        n = i = pageFramesTops && pageFramesTops.length;

        if (!i) continue;

        while (n--) pageFramesTops = pageFramesTops.geometricBounds[0]; // for some reason when one trys to get the geometricBounds[0] from teh everyItems without the elements it return y1, x1 and not just y1 ?-)

        topFrameHeight = pageFramesTops[0];

        topFrame = doc.pages.textFrames[0];

        for (var n = 0; n< i ; n ++) {

            if (pageFramesTops < topFrameHeight) {

                topFrameHeight = pageFramesTops;

                topFrame = doc.pages.textFrames;

            }

        }

        myPageIndex [z++] = {page: topFrame.parentPage, contents: topFrame.contents.toLowerCase()}

    }

    myPageIndex.sort (function (a,b) {return (a.contents.toLowerCase() > b.contents.toLowerCase())});

    l = myPageIndex.length;

    while (l--) myPageIndex.page.move (LocationOptions.AT_BEGINNING);

}

1 reply

Peter Spier
Community Expert
Community Expert
February 13, 2014

I've moved this to the scripting forum. If anyone knows, it will be the users here.

Trevor:
Trevor:Correct answer
Legend
February 13, 2014

This will do it.

But see also http://forums.adobe.com/thread/1082984?tstart=0 for a better workflow.

For some reason the OP over there didn't get back to say thanks and mark the answer as correct .

Trevor

// Script to sort Pages according to alphabetical order of their top TextFrames contents

// by Trevor (www.creative-scripts.com [coming soon]) custom and readymade scripts for InDesign

// http://forums.adobe.com/thread/1405293?tstart=0

// see also http://forums.adobe.com/thread/1082984?tstart=0 for a better workflow

app.doScript("aToZPageSort()", ScriptLanguage.javascript, undefined, UndoModes.FAST_ENTIRE_SCRIPT, "Sort Pages By top text contents");

function aToZPageSort () {

    var doc =  app.documents[0],

          myPageIndex = [],

          l = doc.pages.length,

          topFrameIndex = z= 0, pageFramesTops, i, topFrameHeight, topFrame;

    while (l--) {

        pageFramesTops = doc.pages.textFrames.everyItem().getElements().slice(0);

        n = i = pageFramesTops && pageFramesTops.length;

        if (!i) continue;

        while (n--) pageFramesTops = pageFramesTops.geometricBounds[0]; // for some reason when one trys to get the geometricBounds[0] from teh everyItems without the elements it return y1, x1 and not just y1 ?-)

        topFrameHeight = pageFramesTops[0];

        topFrame = doc.pages.textFrames[0];

        for (var n = 0; n< i ; n ++) {

            if (pageFramesTops < topFrameHeight) {

                topFrameHeight = pageFramesTops;

                topFrame = doc.pages.textFrames;

            }

        }

        myPageIndex [z++] = {page: topFrame.parentPage, contents: topFrame.contents.toLowerCase()}

    }

    myPageIndex.sort (function (a,b) {return (a.contents.toLowerCase() > b.contents.toLowerCase())});

    l = myPageIndex.length;

    while (l--) myPageIndex.page.move (LocationOptions.AT_BEGINNING);

}

NiluferAuthor
Participant
February 13, 2014

Trevor,

Thank you so much! However I am very new in indesign and I even don't know how to add this script into my document

I hope I am not being a pain! Could you  help me on that?

Many thanks...