0 Replies Latest reply on Jul 29, 2014 12:56 PM by rascaly2k

    Creating an index in Design automatically via javascipt

    rascaly2k

      Hello everybody

      I am new to the InDesign world and my experience with In Design has been 5 days. I am trying to create an index based on the content in the InDesign file. I had been scouring the net to find a solution . I was able to find as script from Peter Kahrel, Build an index from text markers. This worked great where I was able to identify words that I wanted to be indexed . It would read those entries and then remove the tags . But I didn't see it generate the index, was wondering if anybody could help me out. The InDesign file just has a text area with the following text on one page. I am not sure why its not adding the contents  in  the <ix> tag  to a seperate index page . Can anybody help me out ?  I am trying to do all of this via javascript , my constraint is all of this all has to be generated via code .

       

      a.indd

      a ret; Catatris. Lum ocut diis vendum aper loctem, Cat L. Abus restabe mulvivi linatqui conena, dissoluter ut ia vis. At Catod consceponsum virmanum ia? quis, corus, quo tum ses consilne oret L. Hum, es ellabem is consultorum diu que consus ommo hem verraci busulie ntidiemerem se, converum tanum remne nonos, con dicertin niam cons horartus.
      Ovius? Nihilis dem nosti pro converet, tum in ventem talessinprei is; nost vives perripsedem des ius, cut L. Vivehen stodi, viris occii sus et; nime int? quo et vivitis. Vales bon ver aut diensula tum obus lica steatu scerim ilnesta que crentis, ad fertam inatisq uamentem dem inihilne no. Pules ac re recus, cae iam. Mari, sedo, conc fit anumus re, factus in test? Lernimus cas la Sp. Dinatur. Nemorumus, estra derfes consuppliis, que pro et L. Viviven atquist grae ad consumur, ni commorum rei peciem ni publin tem estentis. Risquis num tui simus Mae intervive, claris pestrit? Si ignota, Ti. Mumus iacci cons se nonsult ordieni hinvo, unc te auspere nocupie ntemquam il visquiu ventem vis. Serese num etoditi liciemovent fecrio, consuli tam ditero et atifendi, condio consum ad comnit num tam silinat udacchuium iaceristem, obse nondam patil vita, ment.
      Ilis ete, destric moremni terursum incere noximilne hosteris enatum fec omnem publist ortuis rete aucones nossidet atiero inc re foratis se ex mo ego vidi, nonsuperit opublicae prem iam te citudemus, que et avehebat audea rei satudeatiam retique auteret nondam inpri sedius, que ia dem alingultumur horis et? que non terunum cris. Lintimi hiliuratiam furei sessulvirio, nimihicam esus autem obsendamquam por li parid fex nos cre confecio Cupimoe narisquampro eto hos, vivitan terist vit, cultod aut vatis consulici imis cerdiu intemorta, senirmiline iam tesimihin habefactam us avo, or hos ora, manti sentifeconsu ilicies pra priconsili perescris, niumus omnit etissentem, simus condiis. Ex sitine vivilia num idiendiis? Gere ipiore me tendam audam, me contilla ad publictum teatus ret; hucerferi spesignam mente partifecta, ute quidefa crestil ienteniam. Bemulvis, ocum movest demei patui iam manum puludam temus consu consunultor inces endiem host? Unu mod condeperrit, ut apes bon patiam intero in diemus resseniu simissulin Ita nonsupi enestreorei conem pat Catorei scenaritiem aus, sendam, consimure anteatis.’
      <ix>B01448WR</ix>
      <ix>B01448WS </ix>
      <ix>B01448WT </ix>
      <ix>B01448WU </ix>
      <ix>B01448WV </ix>
      Ed se nihicae conferi traetrid iam sedo, Catum nihicam que conincerum serfex mantiu silibus rei se, utem su intis adhumus ficauct usquerem actala iam potandius hil tam in rei se pero vir hostuus sulin hos ellegerum Rompeco nverei publissimus, convertiem Romantrum labus satque iptereme conium tanum, ia efesidem dii is egero, teres et popubliis, notiae, or unumultus publium iam et contio nime omnihil icultui pra quis potanum, C. Lum sente norum me auc fac viven ad C. Ur, num inam, qui senteni hilicie condiust averoximis vatabus locut rebus noximis soltum mora? quit, quium quam ut patuit re non te mandacturaet et fuit, esus? Teri effre actorei puliurnius fure, unt? Nihili, quidelic inemquam in ta L. Ex se oris. Unum horura teate, quitrib efectum iam dicion dem ia nosus vilicaecon turbis, imus con sensuli quidemus ius nunulis pulos prore, contisse diena, maxim constio vatilla immorecri intellabem simus, quidem intidintie auciendeatus egerfectori pon Etrunih ilinulocus
      
      

       

      This is the code ,I took and tweaked a little

      index.jsx

      /*-----------------------------------------------------------
      Build an index from text markers.
      Text markers must look like this (where # is an optional (sub)topic separator):
      
      
      <ix>dog#collie#border collie</ix>dog
      
      
      or this:
      
      
      <ix>dog</ix>
      
      
      That is, the markers either wrap the word to be indexed
      (as in the second example; set "wrapped", below, to "true")
      or they don't, as in the first example (set "wrapped" to "false".
      
      
      Peter Kahrel -- www.kahrel.plus.com
      -----------------------------------------------------------*/
      
      
      #target indesign;
      
      
      //============================================================
      var fileName = "c:/indesignTemplate/a.indd";
      var index_listing=[{}];
      wrapped = true;
      
      
      var doc =openDocument(fileName);
      rebuild_index (doc, wrapped);
      
      
      //============================================================
      
      
      function openDocument(fileName){
         alert("opening Document:" + fileName);
          curFile = File (fileName );
          // check if the file exists
          if (!curFile.exists) {
              alert ( "no template!" );
              exit();
          }
          // open the file
          app.open( curFile);
         
          // set the document active
          return app.activeDocument; 
      }
      
      
      
      
      function rebuild_index (doc, wrapped)
        {
        // "ip" is the insertion point index where page references
        // are placed; see the try clause
        
          var ip = (wrapped == true) ? 4 : -1;  
        
          /*
        if (wrapped == true)
        var ip = 4;
        else
        var ip = -1;
            */
      
          var markers = pagerefs (doc);
        if (markers.length > 0){
        if (doc.indexes.length == 0)
        doc.indexes.add ();
        else
        doc.indexes[0].topics.everyItem().remove();
        var index = doc.indexes[0];
        //mess = create_message (30, 'Building index...')
        for (var i = 0; i < markers.length; i++){
        try{
        var new_topic = create_topic (index, markers[i].contents);
        new_topic.pageReferences.add (
        markers[i].insertionPoints[ip],
        PageReferenceType.currentPage);
        }
        catch (_){}
        }
        if (wrapped == true)
        delete_marker (doc, '</?ix>');
        else
        delete_marker (doc, '<ix>.+?</ix>');
        }
        }
      
      
      
      
      function pagerefs (doc)
        {
        app.findGrepPreferences = app.changeGrepPreferences = null;
        app.findChangeGrepOptions.includeFootnotes = true;
        app.findGrepPreferences.findWhat = '<ix>.+?</ix>';
        return doc.findGrep (true);
        }
      
      
      
      
      // Create topic and any subtopics
      function create_topic (doc_index, str)
        {
        var array = str.replace (/<\/?ix>/g, '').split ('#');
        mess.text = array[0];
        var new_top = doc_index.topics.add (array[0]);
        for (var k = 1; k < array.length; k++)
        new_top = new_top.topics.add (array[k]);
        return new_top;
        }
      
      
      
      
      function find_grep (doc, f)
        {
        app.findGrepPreferences = app.changeGrepPreferences = null;
        app.findGrepPreferences.findWhat = f;
        return doc.findGrep ();
        }
      
      
      function delete_marker (doc, m)
        {
        app.findGrepPreferences = app.changeGrepPreferences = null;
        app.findGrepPreferences.findWhat = m;
        app.changeGrepPreferences.changeTo = '';
        doc.changeGrep ();
        }
      
      

       

      Cheers

      ~InDesignNoob~