2 Replies Latest reply on Jun 26, 2015 7:56 AM by elrayyes

    Column to Index

    elrayyes

      Hi to all,

      I am pretty new to the world of scripting, and trying to learn more. I try to write some scripts to help me speed up some of my tasks, and all is going well, until today.

      My current project requires creating an Index for a catalog. The project contains many tables of products/descriptions (some of which span a few pages long).

      I'm trying to write a script that would add all first column cells contents (minus the first row as it is a header title) to the index, along with page reference; also add a reference marker to the source cells/contents.

       

      Here is my current script so far, which results in an Error Number 24 (Object is not a function) at Line 5.

       

      addToIndex();
      function addToIndex(){
          var myDoc = app.selection[0].tables[0].columns[0];
          for (var i=1; i < myDoc.cells.length; i++){
              app.activeDocument.indexes[0].topics.add(myDoc.cells(i).contents).pageReferences.add(myDoc.cells(i).texts[0].insertionPoints[0]);
          }
      }
      

       

      Any help will be greatly appreciated.

       

      Adham

        • 1. Re: Column to Index
          Peter Kahrel Adobe Community Professional & MVP

          I think you need to do this in two steps: create a topic, then add one or more page references to it:

           

          t = app.activeDocument.indexes[0].topics.add(myDoc.cells(i).contents);
          t.pageReferences.add(myDoc.cells(i).texts[0].insertionPoints[0]);
          
          


          • 2. Re: Column to Index
            elrayyes Level 1

            Thanks Peter for the your reply. But that didn't work either.

            Nevertheless, I found the error, it was actually a syntax error. My variable "i" was in brackets, but should have been in square brackets.

            Here is the correct code:

             

            addToIndex();
            function addToIndex(){
                var myDoc = app.selection[0].tables[0].columns[0];
                for (var i=1; i < myDoc.cells.length; i++){
                    app.activeDocument.indexes[0].topics.add(myDoc.cells[i].contents).pageReferences.add(myDoc.cells[i].texts[0].insertionPoints[0]);
                }
            }
            
            

             

            Cheers,

            Adham