• 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

965

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

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 Beginner ,
Jul 08, 2024 Jul 08, 2024

Copy link to clipboard

Copied

This is very helpful!!

In my index, I have numbers like this "25, 102, 108-109, 155"

I tried to change 
f = "\\d+(-\\d+)?$"

to 

f = "\\d+"

and it changes all the numbers...

But I have one question: I have terms like "COVID-19" and I don't want to change them!

If I locate the terms I don't want to be changed, and change their color to (e.g. Magenta [0, 100, 0, 0])

Is it possible to make the script apply only to numbers with black color, e.g. [0, 0, 0, 100] ?

 

Thank you in advance!

Nick

 

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 ,
Jul 09, 2024 Jul 09, 2024

Copy link to clipboard

Copied

I think you can just insert a word boundary at the start of your find: 

\\b\\d+\\b

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 ,
Jul 09, 2024 Jul 09, 2024

Copy link to clipboard

Copied

quote

[...]

Is it possible to make the script apply only to numbers with black color, e.g. [0, 0, 0, 100] ?


By @Nikos_Var

 

@brian_p_dts's script doesn't reset Find&Change preferences - so you can set whatever you want in the InDesign's UI - BEFORE running script - and it will be preserved and will limit search scope.

 

So you can do a test search - set your color for the text and find first result, then close Find&Change window and run script.

 

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 ,
Jul 09, 2024 Jul 09, 2024

Copy link to clipboard

Copied

To find all number but not the one with Letters/hypen before like in COVID-19, you can use this:

(?<!\u-)\b\d+\b
In Javascript it will be:  (?<!\\u-)\\b\\d+\\b



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
Participant ,
Jul 15, 2024 Jul 15, 2024

Copy link to clipboard

Copied

LATEST

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