9 Replies Latest reply on Aug 1, 2013 1:11 AM by erieru103

    About creating index

    erieru103

      Hi!

       

      I have a script about index that works as the following.

       

      1. Collect the all index from the opened indesign document.
      2. Change the sortby string of the collected index.
      3. Delete all index of the opened indesign document.
      4. Create new index.

       

      After running the script, I found that some index markers's location were shifted.

      But  this script doesn't change the pagereference of index in the step 2 above.

       

      In the another web site I found that says it is a bug.

      It says that when inserting index marker using script, the index markers's location are shifted under a certain condition.

      The condition are the following:

      1. A table is contained on a story same as an index topic.
      2. The table is in front than the index topic.
      3. The table has several rows(it is likely that the number of column does not matter)

       

      In my indesign document sample,  it is sure that a table in accord with the above condition exists.

       

      So, I want to know

      1. Is it a bug really when inserting index marker using script?
      2. If so,  how to avoid this problem?

       

       



        • 1. Re: About creating index
          Peter Kahrel Adobe Community Professional & MVP

          When say "Collect all the index", do you mean the generated index only, or the generated index and the topics and page references in the Index panel? If all you want to do is to change the sortOrder field, then there's no need to delete the topics and page references: you can change the sortOrder fields of existing topics.

           

          As to the table problem, yes, that's a real bug. There is an existing solution (search the forum, the solution was posted in the Swiss HDS forum). Another method is to move all tables into a different story (or into different text frames), add the page references, then return the tables to their correct position.

           

          But as I said, to update the sortOrder field there's no need to delete the page references. Just change the exising topics and update your index.

           

          Peter

          • 2. Re: About creating index
            erieru103 Level 1

            Hi, Peter.

             

            Thank you for your replay.

            I am sorry that I didn't explain clearly and something was wrong.

             

            1.Collect the all index from the opened indesign document.

               This means collect all topics's name, sortorder, page reference in the index panel.

             

            2.Change the sortby string of the collected index.

               This means change the topics's name and sortorder field of the top level only.

                I want the result like the following. From image1 to image2.

               

                Image1

            Image1.JPG

             

                Image2

                Image2.JPG

             

                 3.Delete all index of the opened indesign document.

                     This was wrong. This is deleting all the topics.

             

            If I only change the sort order field of a topic, then the other topics with the same parent will also be changed.

            So I delete all the topics and then add new topic which the sort order field and name field changed(page reference not changed).

             

            In my case, is it possible only change the sort order field?

             

            Best regard.

            • 3. Re: About creating index
              Peter Kahrel Adobe Community Professional & MVP

              Changing a topic's sort order field has the same effect as deleting topic with its page reference and adding the same topic and setting its sort order field.

               

              If you change the sort order field you see the effect straight away. Just try it.

               

              Peter

              • 4. Re: About creating index
                erieru103 Level 1

                Hi, Peter.

                 

                I have tried to changed the sort order field using the following source.

                 

                ---------------------------------------------------------------------------------------

                for i = 1 to myIndex.Topics.Count

                     set myTopic =  myIndex.Topics.Item(i)

                     For j=  myTopic.Topics.count to 1 step -1

                          Set myChdTopic =  myTopic.Topics.Item(j)

                          sortBy = Left(myChdTopic.SortOrder,1)

                          myChdTopic.Parent.SortOrder = sortBy     <-------(1)

                     next

                next

                ----------------------------------------------------------------------------------------

                 

                After executing (1), myChdTopic moved to  the objective position(position a).

                But, the other topic also moved within myChdTopic.Parent to position a.

                I have no idea to prevent the other topics''s movement.

                 

                How should I do to prevent the other topics''s movement.?

                 

                Best regard.

                • 5. Re: About creating index
                  Peter Kahrel Adobe Community Professional & MVP

                  In your outer for-loop you need to go back to front, just as you do with the inner for-loop. Is your code AppleScript? Looks a bit funny with the inconsistency in capitalisation.

                  • 6. Re: About creating index
                    erieru103 Level 1

                    Hi, Peter.

                     

                    My code is not AppleScript. I'm using word VBA.

                     

                    I have changed outer for-loop as the inner for -loop,

                    but the result is same as befor changing outer for-loop.

                     

                    ---------------------------------------------------------------------- -----------------

                    for i = myIndex.Topics.Count to1 step -1

                         set myTopic =  myIndex.Topics.Item(i)

                         For j=  myTopic.Topics.count to 1 step -1

                              Set myChdTopic =  myTopic.Topics.Item(j)

                              sortBy = Left(myChdTopic.SortOrder,1)

                              myChdTopic.Parent.SortOrder = sortBy

                         next

                    next

                    ---------------------------------------------------------------------- ------------------

                     

                    image1 before changing the last child topic sort order within last topic

                    new_Image1.JPG

                    image2 After changing the last child topic sort order, it moved to topic "X".

                    But other child topic like "USB..." also moved to topic "X". Just I want them

                    remain within topic "Z".

                    Image2.JPG

                    Image3.JPG

                    • 7. Re: About creating index
                      erieru103 Level 1

                      Hi, Peter.

                       

                      Could you tell me the page that showing the solution about the table problem?

                      I have searched the page in the Swiss HDS forum, but I couldn't found it

                      because this site is written in German.

                       

                       

                      Best regard

                      • 8. Re: About creating index
                        Peter Kahrel Adobe Community Professional & MVP

                        The fix on HDS is here:

                         

                        http://www.hilfdirselbst.ch/foren/Script_f%FCr_Index_in_InDesign_CS5_P449901.html

                         

                        It is more verbose than necessary. But the idea is simple and fairly easy to implement: before placing a page reference, note the index of the insertionPoint where it (the page reference) should go. Then place it. Then check if it actually landed where it was supposed to. If it didn't, move it. Here's a sample script:

                         

                        if (app.documents[0].indexes.length == 0) app.documents[0].indexes.add();
                        
                        addRef ('distribution');
                        addRef ('information');
                        
                        
                        function addRef (str){
                            var pref, topic = app.documents[0].indexes[0].topics.add(str);
                            app.findGrepPreferences.findWhat = str;
                            var found = app.documents[0].findGrep();
                            for (var i = found.length-1; i > -1; i--){
                                pref = addPageRef (topic, found[i].insertionPoints[0]);
                                // Do whatever else you want to do with the page reference
                            }
                        }
                        
                        
                        function addPageRef (topic, ip) {
                            var target = ip.index;   // The new page ref should go here
                            var pRef = topic.pageReferences.add (ip);  // Add the page ref
                            if (Math.abs(pRef.sourceText.index - target) > 0){   // Did it land where it was supposed to?
                                try {  // No, it didn't: move it
                                    ip.parentStory.characters[pRef.sourceText.index].move (LocationOptions.after, ip);
                                } catch(_){
                                }
                            }
                            return pref;
                        }
                        

                         

                        Peter

                        • 9. Re: About creating index
                          erieru103 Level 1

                          Hi, Peter.

                           

                          The table problem has been solved.

                          Thank you for your reply very much!!

                           

                          Best regard.