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

[CS6][JS][Win]Append page number of citation

Community Beginner ,
Feb 10, 2014 Feb 10, 2014

Copy link to clipboard

Copied

Hi guys,

I hope you can help me with this one, I have a Bibliography page structured like this:

DARWIN Charles Erasmus 7529 (1759–1799) Lorem ipsum dolor sit amet,

   consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore

   et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud

   exercitation ullamco laboris nisi ut aliquip ex ea commodo.

Then I need to search for the body of the book for pages where Darwin were cited then append it to the end of the paragraph which will look like this:

DARWIN Charles Erasmus 7529 (1759–1799) Lorem ipsum dolor sit amet,

   consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore

   et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud

   exercitation ullamco laboris nisi ut aliquip ex ea commodo. [23 35 102 204]

Please take note that the citation on the body of the book may come in different format like, CE Darwin, C.E. Darwin, or Darwin, CE.

I would really appreciate your help.

-CharlesD

TOPICS
Scripting

Views

1.3K

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

correct answers 1 Correct answer

Enthusiast , Feb 11, 2014 Feb 11, 2014

Charles, I had some time during lunch. Find attached a new version. The GREP searches now for pairs. The GREP string can be written certainly shorter, but in this case it is more readable.

So the GREP will find in the first loop C.E. Darwin, C. E. Darwin, CE Darwin or Darwin, C.E. , Darwin, C. E. and Darwin CE and save the corresponding page. Then it will search for 'DARWIN Charles Erasmus' with a applied paragraph style 'myPStyle' and will insert the page names at the end of the paragraph. If th

...

Votes

Translate

Translate
Enthusiast ,
Feb 10, 2014 Feb 10, 2014

Copy link to clipboard

Copied

Hi Charles,

I’m not sure, if I understood the taskcorrectly. So maybe we need some more steps to get to the target.

For convenience, I suppose that the target paragraph has a special paragraphStyle "myPStyle". The script will find each occurrence of Darwin or DARWIN once per page, collect the corresponding page number and write it at the end of the special paragraph.


main ();

function main() {

  var curDoc = app.activeDocument;

  var allPages = curDoc.pages;

   

  var pNumbers = new Array(); 

 

  for ( var i = 0; i < allPages.length; i++ ) {    

    var curPage = allPages;

    var tfs = curPage.textFrames;

   

    app.findGrepPreferences = null;  

    app.findGrepPreferences.findWhat= "(?i)Darwin";  

       

    for ( var t = 0; t < tfs.length; t++ ) {

      var tf = tfs;

      if ( tf.contents != "" )  {

        var res = tf.findGrep();

        if ( res.length > 0 ) {

          pNumbers.push( curPage.name );

          break;

        } // if

      } // if

    } // for

  } // for

  var s = pNumbers.join( " " );

  alert (s);

    

  app.findGrepPreferences.appliedParagraphStyle = curDoc.paragraphStyles.itemByName( "myPStyle" );       

  var result = curDoc.findGrep();

  app.findGrepPreferences = null;

  result[0].paragraphs[0].insertionPoints[-2].contents = "[" + s + "]";

} // main

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 ,
Feb 10, 2014 Feb 10, 2014

Copy link to clipboard

Copied

Hi Kai,

That works amazing. But it will only work for one entry only. So lets say I have multiple entries like:

DARWIN Charles Erasmus 7529 (1759–1799) Lorem ipsum dolor sit amet,

   consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore

   et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud

   exercitation ullamco laboris nisi ut aliquip ex ea commodo.

DARWIN Roqueza Lopena 7319 (1759–1799) Lorem ipsum dolor sit amet,

   consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore

   et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud

   exercitation ullamco laboris nisi ut aliquip ex ea commodo.

DARWIN Charles Robert 7529 (1759–1799) Lorem ipsum dolor sit amet,

   consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore

   et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud

   exercitation ullamco laboris nisi ut aliquip ex ea commodo.

How will I do that? Thank you very much for your response.

-CharlesD

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
Enthusiast ,
Feb 11, 2014 Feb 11, 2014

Copy link to clipboard

Copied

Charles, for you it is very clear how your end result must look. You did not say anything of diferent Darwins at the beginning of your post 😉

I suppose your example is the outpout from the Bibliography, Index or whatever and as you said before and in the bodytext sometimes Darwin is written in different forms.
At the moment the script searches only for Darwin or DARWIN. So I suppose that all your Darwins belongs now to this special one paragraph? So if you have different Darwins, you must search all those different spellings with indiviual searches and apply the output to the individual entries in your index.
Please sent me a example-document with 3 entries and all those different spellings inside the bodytext in the actual state and by hand in the final state. I will try "!" to write a variant of the script above.
Kai

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
Enthusiast ,
Feb 11, 2014 Feb 11, 2014

Copy link to clipboard

Copied

Charles, I had some time during lunch. Find attached a new version. The GREP searches now for pairs. The GREP string can be written certainly shorter, but in this case it is more readable.

So the GREP will find in the first loop C.E. Darwin, C. E. Darwin, CE Darwin or Darwin, C.E. , Darwin, C. E. and Darwin CE and save the corresponding page. Then it will search for 'DARWIN Charles Erasmus' with a applied paragraph style 'myPStyle' and will insert the page names at the end of the paragraph. If the pargraph had alreday something in brackets, this content will be deleted. So you can run the script multiple times.

In the second loop it will find RL Darwin > DARWIN Roqueza Lopena and so on. You can add addtional names or change the GREP expression which determines what is to be found.

Because I am only an advanced beginner in Javascript this could maybe be done easier, but this is my way for today .


main ();

function main() {

    var curDoc = app.activeDocument;

    var allPages = curDoc.pages;

    // [ GREP-Querie, special paragraph ]

    var searchList = [ 

        [ "(?i)((C\\. ?E\\.|CE) Darwin)|(Darwin, (C\\. ?E\\.|CE))", "DARWIN Charles Erasmus" ],

        [ "(?i)((R\\. ?L\\.|RL) Darwin)|(Darwin, (R\\. ?L\\.|RL))", "DARWIN Roqueza Lopena" ],

        [ "(?i)((C\\. ?R\\.|CR) Darwin)|(Darwin, (C\\. ?R\\.|CR))", "DARWIN Charles Robert" ],

    ];

    // loop through the searchList

    for ( var s = 0; s < searchList.length; s++ ) { 

        app.findGrepPreferences = null;  

        app.findGrepPreferences.findWhat = searchList[0];

        var pNumbers = new Array(); 

        // loop through all pages

        for ( var p = 0; p < allPages.length; p++ ) {     

            var curPage = allPages

;

            var tfs = curPage.textFrames;

            // loop through all textframes on the current page

            for ( var t = 0; t < tfs.length; t++ ) {     

                var tf = tfs;

                if ( tf.contents != "" )  {

                    var res = tf.findGrep();

                    if ( res.length > 0 ) {

                        pNumbers.push( curPage.name );

                        break;

                    } // if

                } // if

            } // tfs

        } // allPages

        var pageString = pNumbers.join( " " );

        alert ( searchList[1] + ": " + pageString );

        app.findGrepPreferences = null;

        app.findGrepPreferences.findWhat= searchList[1];

        app.findGrepPreferences.appliedParagraphStyle = curDoc.paragraphStyles.itemByName( "myPStyle" );       

        var result = curDoc.findGrep();

        var para = result[0].paragraphs[0];

        // if the paragraph has already content in '[…]' this content will be deleted

        if ( para.characters[-2].contents == "]" ) {

            app.findGrepPreferences = null;

            app.findGrepPreferences.findWhat = " +\\[[^\\]]+\\]";

            app.changeGrepPreferences.changeTo = "";

            para.changeGrep();       

        }

        para.insertionPoints[-2].contents = " [" + pageString + "]";

    } // searchList

} // main


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 ,
Feb 12, 2014 Feb 12, 2014

Copy link to clipboard

Copied

Hi Kai,

Sorry for late reply I can't sign in yesterday for some reason. Anyway thanks for your effort man I really appreciate it. I must say you're no longer on the beginner area my friend you're way beyond that now. The script works perfectly. But for only few entries but I got hundreds or maybe thousands of names so I guess typing them in the searchList is not an option. What if we tag the names using character style then we search for that character style within our 'myPStyle' and take the value to put automatically in our searchList automatically? You think that's possible? Anyway thanks man and here's some part of the actual document: http://darwinlopena.dx.am/zClients/adobe/sample.zip

-CharlesD

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
Enthusiast ,
Feb 13, 2014 Feb 13, 2014

Copy link to clipboard

Copied

Charles, your entries are not unic. The script works for now, because I describe a list with two pairs.

Your proposal sounds possible for the second part of the list. But can you really guarantee, that the names in the normal text are written as in this 6 examples above? Otherwise the script will not find anything.

If this is true, provide a new example with a shorter list and different names on page 1 (characterStyle only on the name, not the digits), which occur on the following pages in the 6 mentioned spellings.

Anyway I can not promise that I have the time to try this.

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 ,
Feb 13, 2014 Feb 13, 2014

Copy link to clipboard

Copied

Hi Kai,

I managed to extract all the names needed for our searchList. Thanks to you. Trouble now is the script gets the own page number of our myPStyle which should not be the case. Any thoughts?

-CharlesD

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
Enthusiast ,
Feb 13, 2014 Feb 13, 2014

Copy link to clipboard

Copied

I have in the meantime a solution, that extract the names automatically, but it is not perfect at the moment and would need further investigation. So good to here, that you have everything for the search list.

The simplest solution for your problem is, if you can skip those pages, by increase the value for p.

// loop through all pages
        for ( var p = 0; p < allPages.length; p++ ) { 

// loop through all pages
        for ( var p = 1; p < allPages.length; p++ ) { 

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 ,
Feb 18, 2014 Feb 18, 2014

Copy link to clipboard

Copied

LATEST

Finally got this task off my back. What I did was extract all the names (18,000 entries) into a text file then find and replace using regular expression. even this task took me hours as there are a lot of different formats for the names. then when done put the names on our searchList. I had to divide the names into four parts as the indesign is crashing few hours after i ran the script. anyway it takes more than 5 hours for the script to finish running and that's just for 1 part only. So it took more or less 20hrs to finish the job. Whew. Anyway thanks for the script mate. Big help. I wish we could write a complete script for this task so everyone here will benefit from it.

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