TOC and multiple identical entries

Learn / Forums / General InDesign Topics / TOC and multiple identical entries

Viewing 21 reply threads
  • Author
    Posts
    • #84626

      Hi all,
      I’m working on a catalogue and I need to place, at the end of the document, a TOC with all the product codes that appear inside my indesign document.
      The problem is I have the same code (es: 5022030014) on different pages, and of course, when I create my TOC, indesign lists the entries like:
      5022030014…. 1
      5022030014…. 22
      5022030014…. 24
      5022030014…. 33
      etc…

      but what I want is something like this:
      5022030014…. 1, 22, 24, 33

      What should I do?
      Thanks a lot!

    • #84630
      Kelly Vaughn
      Participant

      That’s seems like more of an index. You could probably do a grep search for the duplicates and remove them. But if it’s not too big of a catalog, it my be easier to just do it manually. But I am not a grep person. Perhaps the grep users will have a better idea.

    • #84632
      David Blatner
      Keymaster

      This is for an index, but I wonder if it (or some other Kahrel script) would work: https://www.kahrel.plus.com/indesign/index_update.html

    • #84633

      thx for the advice, the thing is it’s a quite big catalogue (322 page, over 12.000 product codes, I’m not joking).
      The previous designer used to use Xpress, create an index/toc using a character style as a parameter (not a paragraph style, and it was quite useful because she could have codes inside paragraphs lines), save the list of entries (every line had a code and its page number) as a RTF file and then use a script to collapse all the entries in a style she wanted (code n,n,n,n)

      I’m trying to find a way inside indesign and I would like to avoid to add every entry as a topic for and index.
      Right now I found a way, similar to the one of my ex colleague, that is:
      1) from my catalogue file, create a TOC with no page number to have all my entries in a list
      2)copy the list into a new indesign document. save it.
      3) use this script https://www.kahrel.plus.com/indesign/index_from_wordlist.html to add all the entries of the list to my catalogue topics
      4) create an index.

      But I’m wondering if there is an easier way :)

      The other difficulty is to be able to have the codes “free” inside the paragraph, so it would be great to be able to use a character style and not a paragraph style to create the codes entries, but I cannot create a TOC using a character style as a parameter…

    • #84644

      This script might suit your needs. It creates an index based on character styles: https://www.indiscripts.com/category/projects/IndexMatic

    • #84659
      Ari Singer
      Member

      You can leave everything the way you want and use the following cleanup FindChangeList.txt script support to clean up the file in one fell swoop.

      If you’re not familiar with FindChangebyList check it this article, it’s very simple.

      Just replace the default FindChanngelist text support file contents with the following lines:

      
      grep	{findWhat:"(?s)(\\b\\d{8,}\\b)(.+?)(\\d{1,3})(.+?)(\\1(.+?)(\\d{1,3})(.+?))+"}	{changeTo: "", appliedFont:"Times New Roman", fontStyle:"Italic"}	{searchBackwards:false, includeLockedStoriesForFind:false, includeLockedLayersForFind:false, includeHiddenLayers:false, includeMasterPages:false, includeFootnotes:false, kanaSensitive:true, widthSensitive:true} //Find duplicates and apply temporary formatting
      
      grep	{findWhat:"(\\d{1,3})(\\r)", appliedFont:"Times New Roman", fontStyle:"Italic"}	{changeTo: "$1,"}	{searchBackwards:false, includeLockedStoriesForFind:false, includeLockedLayersForFind:false, includeHiddenLayers:false, includeMasterPages:false, includeFootnotes:false, kanaSensitive:true, widthSensitive:true} //Delete returns & add commas
      
      grep	{findWhat:"(?<=,)(\\d{8,}).+?(?=\\d)", appliedFont:"Times New Roman", fontStyle:"Italic"}	{changeTo: ""}	{searchBackwards:false, includeLockedStoriesForFind:false, includeLockedLayersForFind:false, includeHiddenLayers:false, includeMasterPages:false, includeFootnotes:false, kanaSensitive:true, widthSensitive:true} //Delete all unnecessary characters
      
      grep	{findWhat:",$", appliedFont:"Times New Roman", fontStyle:"Italic"}	{changeTo: ""}	{searchBackwards:false, includeLockedStoriesForFind:false, includeLockedLayersForFind:false, includeHiddenLayers:false, includeMasterPages:false, includeFootnotes:false, kanaSensitive:true, widthSensitive:true} //Delete last comma  
      

      What this basically does is find any instances of duplicate entries, apply a temporary font (Times New Roman, Italic), then find any text with said formatting and delete any returns and replace with commas. Then delete all unnecessary text and delete the last comma.

      Just Note: When the script is done, there will be local Times New Roman formatting on all the fixed instances so make sure to select all text and press on the Clear Overrides in Selection button on the bottom of the paragraph styles panel.

    • #84661

      Thx a lot!

      UPDATE:
      I don’t know why but I get an error when I try to run the script.
      I’ve copied your code and pasted it as shown in the post you linked (and here is a link to a screenshot of my script copy/paste: https://drive.google.com/open?id=0B0oislVwKoh-NHFsYUZHS2dNN00)
      And here is the error I get: https://drive.google.com/open?id=0B0oislVwKoh-eE1GdmlzNW9hZHc

      What am I doing wrong?

      • #84670
        Ari Singer
        Member

        Thanks for supplying the screenshot. You’ve made the same mistake I made when I used the FindChangebyList the first time…

        There are two files: one is FindChangeByList.jsx that is found in the Scripts panel and you should not touch this one! If you alter this jsx file nothing will work. Before you do anything, you have to make sure that the jsx file is back to the original. If you didn’t backup the original file then you can find it here. Just download it, extract it, and paste and replace in the original position.

        The other file, and the one you do replace the contents of is the FindChangeList.txt file found in the FindChangeSupport subfolder in the scripts panel. You open that file and replace the contents with the text I provided.

        But it’s also a good idea to save a backup of the original .txt file as well. If you have any questions, don’t hesitate.

    • #86174

      Hi,
      I’m having the same issue but my entries are roman letters and digit, I was wondering how to change the expression to make it works.
      An example on entry would be : STEINEMANN – Arpentage et marquage 585.

      Thanks a lot!

      • #86176
        Ari Singer
        Member

        I can only alter the script if I have an idea of what you’re looking for. Give me a couple of examples (or a screenshot) so I can figure it out.

    • #86177

      Hi,

      Here a screen shot https://www.dropbox.com/s/thjsg2fepzvsewx/example.png?dl=0, I’d like for example to have just one entry for SIKA, etc.

      Thank you very much!

    • #86180
      Ari Singer
      Member

      This time I made it easier. It’s just a regular script that you have to execute, it doesn’t require the FindChangebyList script.

      Read here on how to save the script.

      I’m not sure if it works as expected, so please let me know.

      app.doScript(main, ScriptLanguage.JAVASCRIPT, undefined, UndoModes.ENTIRE_SCRIPT, "Fix Duplicate TOC Entries");
      
      function main() {
          var myDoc = app.activeDocument;
          cleanPrefs();
          app.findGrepPreferences.findWhat = "(?s)(\\b\\w+?\\b)(\\s+?)(\\d{1,3})(\\s+?)(\\1(.+?)(\\d{1,3})(.+?))+";
          var foundText = myDoc.findGrep();
          for (var i = foundText.length - 1; i >= 0; i--) {
              var curEntry = foundText[i];
              app.findGrepPreferences.findWhat = "\\r(?=.)";
              app.changeGrepPreferences.changeTo = ",\\s";
              curEntry.changeGrep();
              app.findGrepPreferences.findWhat = "(?<=,\\s)(\\w+?).+?(?=\\d)";
              app.changeGrepPreferences.changeTo = "";
              curEntry.changeGrep();
              }      
          cleanPrefs();
          }
      
      function cleanPrefs() {
          app.findGrepPreferences = app.changeGrepPreferences = null;
          }
      
    • #86189

      Hi,

      Thank you for your quick answer! I tried the script but I had the following error message : https://www.dropbox.com/s/2yvpii8nxjdvrkz/error_message.png?dl=0

      So I tried to replace the expression in the FindChangedlist text support by the expression in your script. The first line of the text file is :

      grep {findWhat:”(?s)(\\b\\w+?\\b)(\\s+?)(\\d{1,3})(\\s+?)(\\1(.+?)(\\d{1,3})(.+?))+”} {changeTo: “”, appliedFont:”Times New Roman”, fontStyle:”Italic”} {searchBackwards:false, includeLockedStoriesForFind:false, includeLockedLayersForFind:false, includeHiddenLayers:false, includeMasterPages:false, includeFootnotes:false, kanaSensitive:true, widthSensitive:true} //Find duplicates and apply temporary formatting

      I let the remaining lines the same as you posted before. The output from this operation was https://www.dropbox.com/s/fpo9hkh100l84wt/output2.png?dl=0

      It gets better…

      Thanks

    • #86190
      Ari Singer
      Member

      The reason the script failed is because you probably copied the code from your email, and when you do that some characters don’t come through as they should. Try copying the code from my post directly, and try again.

    • #86191

      You’re right, it does something now. But there is a problem, it works on simple entries but when there is a space or a commercial caracter or carater like é (it is in french) it does not work. Furthemore, sometimes there is a number in the entry. I don’t know how to modify the expression and I can maybe introduce some special caracter before the page number to make the task easier.
      Here an example of input and output :
      input https://www.dropbox.com/s/6sb3wsh6lopda1x/example2.png?dl=0
      output https://www.dropbox.com/s/vf4fj5ujp95uw23/output3.png?dl=0

      Thanks a lot!

    • #86196
      Ari Singer
      Member

      To be able to do it correctly I need to have an actual file to test on. Please copy the TOC to a new document and upload it here.

    • #86233
    • #86234

      Hi all,

      not a script, but I had the same question at the weekend, so I did it in this way:

      Find what: (^.+)(\s?\t.+)\r\1\t
      Change to: $1$2,

      The last character in ‘Change to’ is a space!

      The GREP find always two lines. So ‘Change all’ needs to be executed multiple times.

      Kai

    • #86257
      Ari Singer
      Member

      Kai, your GREP string only seems to work in sets of two and not when there are multiple instances.

      Valentin, here’s the updated script that should work as expected. But be aware that it will not work when there’s a regular space between the entry and the number, only a tab is allowed. So make sure that all the entries have proper tabs before the number.

      Please let me know if this does work.

      app.doScript(main, ScriptLanguage.JAVASCRIPT, undefined, UndoModes.ENTIRE_SCRIPT, "Fix Duplicate TOC Entries");
      
      function main() {
          var myDoc = app.activeDocument;
          cleanPrefs();
          app.findGrepPreferences.findWhat = "(.+?)\\s\\d+\\r(\\1\\s\\d+\\r)+";
          var foundText = myDoc.findGrep();
          for (var i = foundText.length - 1; i >= 0; i--) {
             var curEntry = foundText[i];
              app.findGrepPreferences.findWhat = "\\r(?=.)";
              app.changeGrepPreferences.changeTo = ",\\s";
              curEntry.changeGrep();
              app.findGrepPreferences.findWhat = "(?<=, )(.+?)\\t(?=\\d+)";
              app.changeGrepPreferences.changeTo = "";
              curEntry.changeGrep();
              }      
          cleanPrefs();
          }
      
      function cleanPrefs() {
          app.findGrepPreferences = app.changeGrepPreferences = null;
          }
      
    • #86259

      Hi Ari,

      this is true. That’s why I said, you must execute it multiple times.
      It does not take longer than the script to install ;-)

      Kai

      • #86264
        Ari Singer
        Member

        Sorry, Kai. Did not notice that line. It’s faster than a script but has its drawbacks as well. I tried it on the TOC that he provided and the results weren’t perfect.

    • #86268

      Hm, tried it also on the testfile and everything was found?!

    • #86271
      Ari Singer
      Member

      Take the first entry (“Bacs à plantes en béton”)for an example. After I ran the GREP the maximum amount of times, it still is divided in two entries. The culprit seems to be a space that was added in the process at the beginning of the first entry. But this occurs throughout the document with multiple entries.

    • #86273

      Do we have the same testfile? There is no space at the beginning of the first entry! To me it is logical, that the lines must be identical, if I want to find doubles ;-)

      ah: Ari, if you get a space at the beginning, you don’t use my exact GREP!

    • #86275
      Ari Singer
      Member

      Yep! You’re right!

      What happened was that when I copied your “Change To” string, along came a preceding space! (I should’ve been more careful, because this happens so often!). It does work now as expected. Thanks!

Viewing 21 reply threads
  • You must be logged in to reply to this topic.
>