Skip to main content
Participant
October 16, 2012
Pregunta

Can you sort indesign pages alphabetically?

  • October 16, 2012
  • 2 respuestas
  • 4676 visualizaciones

I have a document with over 200 page and I want to sort the pages alpahetically after the heading on every page.The headings have one paragrah style. The document is singel pages, but there is two text frames on ever page. Many pages have also the same heading, so I hope to sort them in the  same order in which the document is now.

If you see the images under, I want to sort the pages alphabetically after the "heading" in bold to the right (txt:Best Buys Natural Wines)

Is it possible with a script or something else?

Este tema ha sido cerrado para respuestas.

2 respuestas

Trevor:
Legend
October 16, 2012

Ok This is what you were after.

This assumes that you use a Paragraph style for your header AND THERE IS ONLY ONE HEADER ON EACH PAGE WHICH IS ONLY ONE PARAGRAPH LONG


// Script by Trevor to sort Pages according to alphabetical order of Page Headers

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

var doc =  app.documents[0], myHeaders, l;

app.changeGrepPreferences = app.findGrepPreferences = null;

app.findGrepPreferences.appliedParagraphStyle = "My Header";

// Change above to the name of header style

myHeaders = doc.findGrep();

for (n=0; n < myHeaders.length-1; n++) $.writeln([myHeaders.contents]);

myHeaders.sort (function (a,b) {if (a.contents.toLowerCase() > b.contents.toLowerCase())  return 1 else return -1})

l = myHeaders.length;

while (l--) myHeaders.parentTextFrames[0].parentPage.move (LocationOptions.AT_BEGINNING);

Participant
April 3, 2016

thanks ..awsome script i've been searching for a while

but i need to add certain lines to this script hope you can help me

now i have these paragraph style (for certain chapters)

-Palm Trees ---paragraph style for chapter 1

-Trees ---paragraph style for chapter 2

-Shrubs---paragraph style for chapter 3

-Ground Covers---paragraph style for chapter 4

-Climbers---paragraph style for chapter 4

-Succulents---paragraph style for chapter 4

i want to arrange the pages that have these paragraph styles alphabetically in that exact order (arranging the paragraph)...can you help me in this?

be noted that each chapter has its own Master Page

Participant
April 4, 2016

i've tried my luck in editing your code

var doc =  app.documents[0], Palmtrees, Trees, Shrubs, GroundCovers, Climbers, Succulents, l;

app.changeGrepPreferences = app.findGrepPreferences = null; 

app.findGrepPreferences.appliedParagraphStyle = "Plant Name (Palm trees)";

app.findGrepPreferences.appliedParagraphStyle = "Plant Name (Trees)";

app.findGrepPreferences.appliedParagraphStyle = "Plant Name (Shrubs)";

app.findGrepPreferences.appliedParagraphStyle = "Plant Name (GroundCovers)";

app.findGrepPreferences.appliedParagraphStyle = "Plant Name (Climbers)";

app.findGrepPreferences.appliedParagraphStyle = "Plant Name (Succulents)";

// Change above to the name of  Paragraph Styles  

Succulents = doc.findGrep(); 

for (n=0; n < Succulents.length-1; n++) $.writeln([Succulents.contents]); 

Succulents.sort (function (a,b) {if (a.contents.toLowerCase() > b.contents.toLowerCase())  return 1 else return -1}) 

l = Succulents.length; 

while (l--) Succulents.parentTextFrames[0].parentPage.move (LocationOptions.AT_BEGINNING);

Climbers = doc.findGrep(); 

for (n=0; n < Climbers.length-2; n++) $.writeln([Climbers.contents]); 

Climbers.sort (function (a,b) {if (a.contents.toLowerCase() > b.contents.toLowerCase())  return 2 else return -2}) 

l = Climbers.length; 

while (l--) Climbers.parentTextFrames[0].parentPage.move (LocationOptions.AT_BEGINNING);

for (n=0; n < GroundCovers.length-3; n++) $.writeln([GroundCovers.contents]); 

GroundCovers.sort (function (a,b) {if (a.contents.toLowerCase() > b.contents.toLowerCase())  return 3 else return -3}) 

l = Climbers.length; 

while (l--) GroundCovers.parentTextFrames[0].parentPage.move (LocationOptions.AT_BEGINNING);

for (n=0; n < Shrubs.length-4; n++) $.writeln([Shrubs.contents]); 

Shrubs.sort (function (a,b) {if (a.contents.toLowerCase() > b.contents.toLowerCase())  return 4 else return -4}) 

l = Shrubs.length; 

while (l--) Shrubs.parentTextFrames[0].parentPage.move (LocationOptions.AT_BEGINNING);

for (n=0; n < Trees.length-5; n++) $.writeln([Trees.contents]); 

Trees.sort (function (a,b) {if (a.contents.toLowerCase() > b.contents.toLowerCase())  return 5 else return -5}) 

l = Trees.length; 

while (l--) Trees.parentTextFrames[0].parentPage.move (LocationOptions.AT_BEGINNING);

for (n=0; n < Palmtrees.length-6; n++) $.writeln([Palmtrees.contents]); 

Palmtrees.sort (function (a,b) {if (a.contents.toLowerCase() > b.contents.toLowerCase())  return 6 else return -6}) 

l = PalmTrees.length; 

while (l--) Palmtrees.parentTextFrames[0].parentPage.move (LocationOptions.AT_BEGINNING);

alert("Finished!");

but sadly i get this error ...

can you please help me?

Trevor:
Legend
October 16, 2012

Do the pages contain linked stories?

If not you can script it easily with the move command