• Global community
    • Language:
      • Deutsch
      • English
      • EspaƱol
      • FranƧais
      • PortuguĆŖs
  • ę—„ęœ¬čŖžć‚³ćƒŸćƒ„ćƒ‹ćƒ†ć‚£
    Dedicated community for Japanese speakers
  • ķ•œźµ­ ģ»¤ė®¤ė‹ˆķ‹°
    Dedicated community for Korean speakers
Exit
0

Can you sort indesign pages alphabetically?

New Here ,
Oct 16, 2012 Oct 16, 2012

Copy link to clipboard

Copied

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?

Skjermbilde+2012-10-11+kl.+12.03.18.png

TOPICS
Scripting

Views

3.8K

Translate

Translate

Report

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
Guru ,
Oct 16, 2012 Oct 16, 2012

Copy link to clipboard

Copied

Do the pages contain linked stories?

If not you can script it easily with the move command

Votes

Translate

Translate

Report

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
Guru ,
Oct 16, 2012 Oct 16, 2012

Copy link to clipboard

Copied

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

Votes

Translate

Translate

Report

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
Guru ,
Oct 16, 2012 Oct 16, 2012

Copy link to clipboard

Copied

It also asumes that every page has a header

Votes

Translate

Translate

Report

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
Guru ,
Oct 20, 2012 Oct 20, 2012

Copy link to clipboard

Copied

I thought I made I nice little script here that answered your question.

With all those bottles of wine I expected at least a "Cheers mate"

Any reason why you didn't mark the question as correct?

Votes

Translate

Translate

Report

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
New Here ,
Apr 03, 2016 Apr 03, 2016

Copy link to clipboard

Copied

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

Votes

Translate

Translate

Report

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
New Here ,
Apr 04, 2016 Apr 04, 2016

Copy link to clipboard

Copied

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 ...

error..png

can you please help me?

Votes

Translate

Translate

Report

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
Guru ,
Apr 04, 2016 Apr 04, 2016

Copy link to clipboard

Copied

Hi

I'm too busy just now, to look into it either-way I don't understand what you are after.

If you split the document into chapters would that not help?

Trevor

Votes

Translate

Translate

Report

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
New Here ,
Apr 05, 2016 Apr 05, 2016

Copy link to clipboard

Copied

yes it would help the thing that is iam new to indesign scripting ...and i was just trying my luck

Votes

Translate

Translate

Report

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
Participant ,
Apr 05, 2016 Apr 05, 2016

Copy link to clipboard

Copied

The error message tells you what the error is - GroundCovers is not defined. It is declared but you are not assigning it any value.

Your basic code would be:

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

app.changeGrepPreferences = app.findGrepPreferences = null;


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

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


// then you repeat:


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

Climbers = doc.findGrep();

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

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

l = Climbers.length;  

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


etc... Basically you need to change what you are searching for BEFORE every search.


Let me know if this helps.


Michael

Votes

Translate

Translate

Report

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
New Here ,
Apr 12, 2016 Apr 12, 2016

Copy link to clipboard

Copied

thanks so much Michael, worked perfectly




Votes

Translate

Translate

Report

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
New Here ,
Aug 04, 2016 Aug 04, 2016

Copy link to clipboard

Copied

Hello,

I found this script and it helps me alot, but i would like, if it's posible, to ignore numbers or the first 4 characters.

My problem is that my paragraph contains "year + name", and i want the pages sorted just by name. Now it sorts everything chronologicaly not alphabeticaly.

Votes

Translate

Translate

Report

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
Guru ,
Aug 04, 2016 Aug 04, 2016

Copy link to clipboard

Copied

Hi Mad

Not tested but replace

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

with

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

HTH

Trevor

Votes

Translate

Translate

Report

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
Participant ,
Aug 04, 2016 Aug 04, 2016

Copy link to clipboard

Copied

I would replace like this:

myHeaders.sort (function (a,b) {if (a.contents.toLowerCase().replace(/^\d{4}/,"")  > .contents.toLowerCase()).replace(/^\d{4}/,"")
  return 1 else return -1});

//if the year is at the beginning of the paragraph but watch for trailing spaces

or

myHeaders.sort (function (a,b) {if (a.contents.toLowerCase().replace(/\d{4}/,"")  > .contents.toLowerCase()).replace(/\d{4}/,"")
  return 1 else return -1});

//if year is not at the beginning

Michael

Votes

Translate

Translate

Report

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
Guru ,
Aug 04, 2016 Aug 04, 2016

Copy link to clipboard

Copied

Yes, i was being very lazy. But as long as the paragraphs are setup as described I don't think one would see any difference.

Votes

Translate

Translate

Report

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
New Here ,
Aug 05, 2016 Aug 05, 2016

Copy link to clipboard

Copied

Thank you both for your interest and help, but i get an error for both your lines.

". does not have a value"

The year is at the begining. If it was at the end the first script would have worked

Votes

Translate

Translate

Report

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
Guru ,
Aug 05, 2016 Aug 05, 2016

Copy link to clipboard

Copied

myHeaders.sort(function(a, b) {

    if (a.contents.toLowerCase().replace(/\d{4}/, "") > b.contents.toLowerCase().replace(/\d{4}/, "")) return 1;

    else return -1;

});

Sorry there where typos in both our examples. The above should work.

Votes

Translate

Translate

Report

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
New Here ,
Aug 05, 2016 Aug 05, 2016

Copy link to clipboard

Copied

LATEST

Thank you very much. It worked perfectly!

Votes

Translate

Translate

Report

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