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

ID script to increase numbers?

Explorer ,
Apr 15, 2022 Apr 15, 2022

Copy link to clipboard

Copied

I am working on a new edition of a book that has grown by two pages in the middle of the book. I need to update the manually created index to reflect this repagination. I have a memory of a script that would search out page ranges and then could increase it by a set amount (in my case, anything from pages 204–422 becomes 206–424 [+2]). I have done an exhaustive search online and can't track down anything that would work.

 

Anyone know of a script that can do such a miracle?

TOPICS
Scripting

Views

476

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
Community Expert ,
Apr 15, 2022 Apr 15, 2022

Copy link to clipboard

Copied

Copy the index to a new document then try this?

 

 

var d = app.activeDocument;
var f = "\\d+(-\\d+)?$";
app.findGrepPreferences.findWhat = f;
var fs = d.findGrep();
var t, i, j, s;
for (var i = 0; i < fs.length; i++) {
    t = fs[i].contents.split("-");
    s = "";
    for (j = 0; j < t.length; j++) {
        if (j == 0) {
            s += (Number(t[j]) + 2).toString();
        } else {
            s += "-" + (Number(t[j]) + 2).toString();
        }
    }
    fs[i].contents = s;
}

 

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
Explorer ,
Apr 15, 2022 Apr 15, 2022

Copy link to clipboard

Copied

Not being a script writer and only a GREP novice, I am trying to read this code to figure out what it does. It seems to find a number range and then adds +2 to the number. Since this is an index, not all numbers are ranges. My biggest "issue" is that not all numbers need to be increase, just those after the two new pages were added. Per the attached screen grab, you can see that this index uses a variety of numbering and not all numbers should change. 

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
Community Expert ,
Apr 15, 2022 Apr 15, 2022

Copy link to clipboard

Copied

Perhaps copying just the text you need to a new doc - run the script - and copy it back.

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
Explorer ,
Apr 15, 2022 Apr 15, 2022

Copy link to clipboard

Copied

I'll give it a shot. Thx

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
Community Expert ,
Apr 16, 2022 Apr 16, 2022

Copy link to clipboard

Copied

LATEST

Edit: I had an error in the GREP; it now accommodates index entries that are not ranges, and those that are. Let us know how it went. 

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
Community Expert ,
Apr 15, 2022 Apr 15, 2022

Copy link to clipboard

Copied

@Steve Straus I have send you a personal script for that in your private message... 

 

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