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

InDesign javascript: find text that occurs after findGrep() result

New Here ,
Oct 03, 2017 Oct 03, 2017

I currently have a script that uses findGrep() to locate item numbers on a catalog page and then print the item number found and the page number it was on. I would like to modify this to also print the price of the item. The price occurs in the text somewhere following the item number and starts with a dollar sign followed by at least three digits (regex would be something like "\$[0-9][0-9][0-9]+"). How can I search for the price starting from the position of the found item number? Thanks

1.6K
Translate
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
LEGEND ,
Oct 03, 2017 Oct 03, 2017

Hi Roger,

Code and screenshot please! 

(^/)

Translate
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 ,
Oct 03, 2017 Oct 03, 2017

Here is the code snippet that finds the item numbers ("SKU") in a catalog spread and prints them along with the page number. Many variable declarations not shown.

skus is the array of Text objects returned by findGrep().

// a regular expression to match item numbers/SKUs
var     regex = "[0-9][0-9]-[0-9][0-9][0-9][0-9]+[A-Z]*";

[...]

// initialize search preferences

app.findGrepPreferences = NothingEnum.NOTHING;

app.changeGrepPreferences = NothingEnum.NOTHING;

app.findChangeGrepOptions.includeMasterPages = false;

app.findGrepPreferences.findWhat = regex;

[...]

skus = doc.findGrep();

if ((nskus = skus.length) > 0)

{

     // found at least one: process each SKU

     for (j = 0; j < nskus; j++)

     {

          // get the SKU as a text object that we can manipulate with string methods

          sku = skus.texts[0].contents;

          if ((hyphen = sku.indexOf("-")) > 1)

          {

               // well, of course there's a hyphen: it's part of our regex;

               // we just don't want to print it

               if (skus.parentTextFrames[0].parentPage)

               {

                    // item is actually on the page, not on the pasteboard

                    websku = sku.substr(hyphen - 2, 2) + sku.substr(hyphen + 1);

                    file.write(websku + "\t" + skus.parentTextFrames[0].parentPage.name + "\n");

               } // end if SKU is actually on a page (not on the pasteboard)

          } // end if there's a hyphen in the SKU

     } // end for each SKU

} // end if any SKUs present

[...]

​Domo arrigato.

Translate
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 ,
Oct 03, 2017 Oct 03, 2017

Let's not discuss this in the general forum, but in the more appropriate Scripting forum instead (where you also asked this: InDesign javascript: search for text that follows findGrep() result ).

Translate
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 ,
Oct 03, 2017 Oct 03, 2017
LATEST

Sorry, you're right. But I didn't discover the scripting forum until after I'd posted it here.

Translate
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