6 Replies Latest reply on Dec 5, 2008 1:04 AM by stoereee

    [CS3] Search Index Markers

    stoereee Level 1
      Is there a way to search for index markers and then get the content from it to put it in a new created anchored inline textframe? I wan't to create side-heading like in Framemaker.
        • 1. Re: [CS3] Search Index Markers
          Peter Kahrel Adobe Community Professional & MVP
          I use the script below to convert page references to text. The contents of the references is placed at the index marker, using the format bla. Any subtopics are separated by #.

          Peter

          index2text (app.activeDocument);
          delete_index (app.activeDocument);

          function index2text (doc)
             {
             var tops = doc.indexes[0].allTopics;
             for (var i = 0; i < tops.length; i++)
                for (var j = tops[i].pageReferences.length-1; j > -1; j--)
                   tops[i].pageReferences[j].sourceText.contents =
                         '<ix>' + topic_path (tops[i], tops[i].name) + '</ix>';
             }

          // create topic string. Subtopics are separated by '#'
          function topic_path (top, str)
             {
             if (top.parent.constructor.name == 'Index')
                return str;
             else
                return topic_path (top.parent, top.parent.name + '#' + str)
             }

          function delete_index (doc)
             {
             // delete page references and topics
             doc.indexes[0].topics.everyItem().pageReferences.everyItem().remove();
             doc.indexes[0].topics.everyItem().remove();
             }
          • 2. Re: [CS3] Search Index Markers
            stoereee Level 1
            The Script works fine. But how can I put anchored inline textframe at Index marker position?
            • 3. Re: [CS3] Search Index Markers
              Peter Kahrel Adobe Community Professional & MVP
              Ah -- I thought you just wanted to know about the index markers. To create side headings, just insert a text frame at the index marker. The script needs an object style "sidebar" that has all the necessary settings. It now creates sidebars 70 points wide, you can change that in the line
              >sidebar.geometricBounds = [0,0,10,70];

              Change 70 to the width you need (you can use other units like this: "20mm"). I've tried this on a simple document and it worked fine. Maybe the orientation of the ruler plays a role, I don't know.

              Peter

              index2text (app.activeDocument);
              
              delete_index (app.activeDocument);

              function index2text (doc)
                 {
                 var tops = doc.indexes[0].allTopics;
                 for (var i = 0; i < tops.length; i++)
                    for (var j = tops[i].pageReferences.length-1; j > -1; j--)
                       {
                       var ip = tops[i].pageReferences[j].sourceText;
                       var p_ref = topic_path (tops[i], tops[i].name);
                       side_note (ip, p_ref)
                       }
                 }

              // create topic string. Subtopics are separated by '#'
              function topic_path (top, str)
                 {
                 if (top.parent.constructor.name == 'Index')
                    return str;
                 else
                    return topic_path (top.parent, top.parent.name + '#' + str)
                 }

              function delete_index (doc)
                 {
                 // delete page references and topics
                 doc.indexes[0].topics.everyItem().pageReferences.everyItem().remove();
                 doc.indexes[0].topics.everyItem().remove();
                 }

              function side_note (ins_point, s)
                 {
                 var sidebar = ins_point.textFrames.add ();
                 sidebar.geometricBounds = [0,0,10,70];
                 sidebar.appliedObjectStyle = app.activeDocument.objectStyles.item ('sidebar');
                 sidebar.contents = s;
                 sidebar.fit (FitOptions.frameToContent);
                 }
              • 4. Re: [CS3] Search Index Markers
                Martin Fischer Level 2
                Hi Peter,

                what a nice script!

                I have took the liberty of doing some modifications to take use of the conditional text feature in InDesign CS4. So one can make the previous index entries visible or not.

                Here it goes with the (new) function 'conditional_note()' instead of 'side_note()':

                // index2text.jsx
                // based on a script of Peter Kahrel, modified to take use of InDesign CS4 conditional text

                Object.prototype.get = function( )
                {
                   try {
                      var myObject = this.item( arguments[0].name );
                      myObject.name;
                   }
                   catch (e) {
                      var myObject = this.add( arguments[0] );
                   }
                   return myObject;
                }

                var myConditionSet = app.activeDocument.conditions.get( {name:'Index',  indicatorMethod:ConditionIndicatorMethod.USE_HIGHLIGHT} )
                index2text (app.activeDocument);
                //delete_index (app.activeDocument);
                myConditionSet.visible = false;

                function index2text (doc)
                   {
                   var tops = doc.indexes[0].allTopics;
                   for (var i = 0; i < tops.length; i++)
                      for (var j = tops[i].pageReferences.length-1; j > -1; j--)
                         {
                         var ip = tops[i].pageReferences[j].sourceText;
                         var p_ref = topic_path (tops[i], tops[i].name);
                         conditional_note (ip, p_ref)
                         }
                   }

                // create topic string. Subtopics are separated by '#'
                function topic_path (top, str)
                   {
                   if (top.parent.constructor.name == 'Index')
                      return str;
                   else
                      return topic_path (top.parent, top.parent.name + '#' + str)
                   }

                function delete_index (doc)
                   {
                   // delete page references and topics
                   doc.indexes[0].topics.everyItem().pageReferences.everyItem().remove();
                   doc.indexes[0].topics.everyItem().remove();
                   }

                function conditional_note (ins_point, s)
                   {
                   ins_point.appliedConditions = myConditionSet;
                   ins_point.contents = s;
                   }

                function side_note (ins_point, s)
                   {
                   var sidebar = ins_point.textFrames.add ();
                   sidebar.geometricBounds = [0,0,10,70];
                   sidebar.appliedObjectStyle = app.activeDocument.objectStyles.get( { name:'sidebar' } );
                   sidebar.itemLayer = app.activeDocument.layers.get( { name:'sidebar' } );
                   sidebar.contents = s;
                   sidebar.fit (FitOptions.frameToContent);
                   }


                Thanks
                Martin Fischer
                • 5. Re: [CS3] Search Index Markers
                  Peter Kahrel Adobe Community Professional & MVP
                  Thanks, Martin, that will be useful.

                  Peter
                  • 6. Re: [CS3] Search Index Markers
                    stoereee Level 1
                    Thank you both, this is very helpfull!