7 Replies Latest reply on Dec 12, 2016 8:04 AM by rndlm

    Fixing *multiple* Paragraph Style combinations at once

    rndlm

      Hi all,

       

      I've adjusted Thomas Silkjaer's (famous) script for "Fixing paragraph style combinations" in order to handle multiple Header+First Paragraph combinations -- such as apply Paragraph Style [x] instead of [y] if it follows a header (H1/H2/H3 etc).

      But his script is dialog-based, and I wanted to fix multiple paragraph style combinations at once without user interaction required, so I embedded his script multiple times in one single script and hard-coded the specific Paragraph Styles in it.

       

      See the script below; it may not be the most efficient solution, but it works for me.

      The only problem is that sometimes a specific Paragraph Style (combination) is not present in the document -- and then the script just returns an error and doesn't proceed to the next block.

       

      The error is

      Error Number: 21
      Error String: undefined is not an object
      

       

      and is triggered because of this part (to be found below at line 71):

        change_first_list[myCounter].appliedParagraphStyle = change_first_paragraph;
        change_second_list[myCounter].appliedParagraphStyle = change_second_paragraph;
      

      Which is not a surprise, because the script cannot find the Paragraph Styles in the document.

       

      My question: does anybody know how I can "catch" and ignore this error, so that the script jumps to the suppressed Alert and proceeds to the next block?

       

      Thanks!

      Randy

       

      PS. Oh, how I would like CSS-like style selectors for InDesign, so that I can do things like

      p.style + p.style {margin-top: 0}
      

       

      ====
      The script:

      /*
        Fixing paragraph style combinations
        Version: 1.2
        Script by Thomas Silkjær
        http://indesigning.net/
        */
      
        var the_document = app.documents.item(0);
      
        // Create a list of paragraph styles
        var list_of_paragraph_styles = [];
        var all_paragraph_styles = [];
        the_document.paragraphStyles.everyItem().name;
        for(i = 0; i < the_document.paragraphStyles.length; i++) {
        list_of_paragraph_styles.push(the_document.paragraphStyles[i].name);
        all_paragraph_styles.push(the_document.paragraphStyles[i]);
        }
      
        for(i = 0; i < the_document.paragraphStyleGroups.length; i++) {
        for(b = 0; b < the_document.paragraphStyleGroups[i].paragraphStyles.length; b++) {
        list_of_paragraph_styles.push(the_document.paragraphStyleGroups[i].name+'/'+the_document.paragraphStyleGroups[i].paragraphStyles[i].name);
        all_paragraph_styles.push(the_document.paragraphStyleGroups[i].paragraphStyles[i]);
        }
        }
      
        // Make the dialog box for selecting the paragraph styles
        // I've removed code that arranges the dialog box!
      
        // Define paragraph styles
        var find_first_paragraph = the_document.paragraphStyles.item("CHAP_H1");
        var find_second_paragraph = the_document.paragraphStyles.item("CHAP_TXT");
        var change_first_paragraph = the_document.paragraphStyles.item("CHAP_H1");
        var change_second_paragraph = the_document.paragraphStyles.item("CHAP_TXT_BEFORE");
      
        // Set find grep preferences to find all paragraphs with the first selected paragraph style
        app.findChangeGrepOptions.includeFootnotes = false;
        app.findChangeGrepOptions.includeHiddenLayers = false;
        app.findChangeGrepOptions.includeLockedLayersForFind = false;
        app.findChangeGrepOptions.includeLockedStoriesForFind = false;
        app.findChangeGrepOptions.includeMasterPages = false;
      
        app.findGrepPreferences = NothingEnum.nothing;
        app.findGrepPreferences.appliedParagraphStyle = find_first_paragraph;
        app.findGrepPreferences.findWhat = "$";
      
        //Search the current story
        var the_story = app.selection[0].parentStory;
        var found_paragraphs = the_story.findGrep();
      
        var change_first_list = [];
        var change_second_list = [];
      
        // Loop through the paragraphs and create a list of words and mark them as index words
        myCounter = 0;
        do {
        try {
        // Create an object reference to the found paragraph and the next
        var first_paragraph = found_paragraphs[myCounter].paragraphs.firstItem();
        var next_paragraph = first_paragraph.paragraphs[-1].insertionPoints[-1].paragraphs[0];
        // Check if the next paragraph is equal to the find_second_paragraph
        if(next_paragraph.appliedParagraphStyle == find_second_paragraph) {
        change_first_list.push(first_paragraph);
        change_second_list.push(next_paragraph);
        }
        } catch(err) {}
        myCounter++;
        } while (myCounter < found_paragraphs.length); 
        // Apply paragraph styles
        myCounter = 0;
        do {
        change_first_list[myCounter].appliedParagraphStyle = change_first_paragraph;
        change_second_list[myCounter].appliedParagraphStyle = change_second_paragraph;
        myCounter++;
        } while (myCounter < change_first_list.length);
      
        //alert("Done fixing pairs!");
        // Now starts the next block of code, to which I want to jump in case the Paragraph Style is not present in the document.
      
        • 1. Re: Fixing *multiple* Paragraph Style combinations at once
          Trevorׅ Adobe Community Professional

          Hi

           

          VERY MUCH without looking at the script I would guess you could change

           

          From

          do {  
            change_first_list[myCounter].appliedParagraphStyle = change_first_paragraph;  
            change_second_list[myCounter].appliedParagraphStyle = change_second_paragraph;  
            myCounter++;  
            } while (myCounter < change_first_list.length);  
          

           

          To

           do {
               try {
                   change_first_list[myCounter].appliedParagraphStyle = change_first_paragraph;
                   change_second_list[myCounter].appliedParagraphStyle = change_second_paragraph;
               } catch (e) {}
               myCounter++;
           } while (myCounter < change_first_list.length);
          

           

           

          HTH

           

          Trevor

          • 2. Re: Fixing *multiple* Paragraph Style combinations at once
            Trevorׅ Adobe Community Professional

            P.s.

             

            app.selection[0].properties = app.selection[1].properties = {strokeColor:app.activeDocument.swatches[5], strokeWeight:5}

            is the same idea as the css selectors

            So you could use.

            p.style1.properties = p.style2.properties = {AAAA: aaaa, BBBB: bbbb, ETC: etc}

            • 3. Re: Fixing *multiple* Paragraph Style combinations at once
              Wosven Level 1

              Hello,

              I modified this script too.

              Here my versions, if it can help.

               

              This first one add an optional search option (text or GREP), for the 1st style

              a clear overrides option

              and if cursor is in a paragraph, select this paragraph' style and the next style automatically

              If nothing is selected, an alert display some help

               

              The long first part add translation (french, english)

               

              //DESCRIPTION: change paragraphs styles with search option
              //*------------------------------
              //
              // Script for InDesign CS4-+.
              // septembre 2015
              // sw
              // based on
              //    Script by Thomas Silkjær
              //    http://indesigning.net/
              //
              // Replace 2 consecutive paragraph styles with 2 other styles
              // option for searching in first paragraph style (text or GREP)
              // and option to delete overrides (character styles, bold, italic...) not include in paragraph styles
              // search in story or selected text
              //------------------------------*//
              if (app.locale.toString() == "FRENCH_LOCALE") {
              
                  var infos = {
                      scrName:        "Change paragraphs styles", 
                      scrVers:        "0.1", 
                      defStyle:        "Sans", 
                      _infos1 :     "Simples remplacements :\n===============\n Utiliser uniquement les choix de style pour remplacer les styles (1) ou (2) par les styles (3) et (4).\n",
                      _infos2 :     "Ne pas oublier de remplir les styles (3) et (4), même par des styles identiques si l'on ne veut pas en changer un.\n",
                      _infos3 :     "\nRecherches :\n============\n Permet de cherche du texte ou des GREP contenu dans le style (1) uniquement.\n",
                      _infos4 :     "\nRemplacement de styles de caractère :\n========================\n Effacera en même temps les styles de caractères utilisés dans ces paragraphes (= utiliserle style de caractère [Sans]).",
                      alert1 :     "Mauvaise sélection !",
                      alert2 :     "Aucun paragraphe suivant !",
                      panel1 :     "Options de recherche :",
                      check1 :     "Recherche de texte",
                      stT1 :         "Texte :",
                      stT2 :         "Texte ou laisser vide",
                      check2 :     "Recherche GREP",
                      stT3 :         "GREP :",
                      stT4 :         "GREP ou laisser vide",
                      check3 :     "Supprimer les remplacements (styles de caractère)",
                      help1 :     "Enlèvera aussi les styles de caractères des paragraphes",
                      panel2 :     "Choix des styles :",
                      f1 :         'Si (1) :',
                      f2 :         "Liste des styles de paragraphe disponibles\r",
                      f3 :         'est suivi de (2) :',
                      f4 :         'remplacer (1) par (3) :',
                      f5 :         'et (2) par (4) :',
                      ok :         "Valider",
                      cancel :     "Annuler",
                      alert3 :     " remplacement(s) fait(s) !"
                  };
              }
              else {
              
                  var infos = {
                      scrName:    "Change paragraphs styles", 
                      scrVers:    "0.1", 
                      defStyle:    "None", 
                      _infos1 :     "Simples replacements:\n===============\n Use only style selections for relacing styles (1) or (2) with styles (3) and (4).\n",
                      _infos2 :     "Do not forget to select styles (3) and (4), with same style if you don't want to replace a style.\n",
                      _infos3 :     "\nSearch:\n============\n Only search text or GREP in style (1).\n",
                      _infos4 :     "\nDelete character styles:\n========================\n Erase characters styles overrides while applying paragraph styles (= use character style [None]).",
                      alert1 :     "Bad selection!",
                      alert2 :     "No next paragraph!",
                      panel1 :     "Search options:",
                      check1 :     "Search text",
                      stT1 :         "Text:",
                      stT2 :         "Text or nothing",
                      check2 :     "Search GREP",
                      stT3 :         "GREP :",
                      stT4 :         "GREP or nothing",
                      check3 :     "Delete overrides (character styles)",
                      help1 :     "On applying paragraph styles, delete overrides",
                      panel2 :     "Styles selections:",
                      f1 :         'If (1) :',
                      f2 :         "List of paragraph styles\r",
                      f3 :         'is followed by (2) :',
                      f4 :         'remplace (1) with (3) :',
                      f5 :         'and (2) with (4) :',
                      ok :         "OK",
                      cancel :     "Cancel",
                      alert3 :     " replacement(s)!"
                  };
              
              }
                      
                      
                      
              // Globals
              const wScriptName = infos.scrName;
              const wScriptVersion = infos.scrVers;
              var myInDesignVersion = Number(String(app.version).split(".")[0]);
              
              var defaultStyle = infos.defStyle; 
              
              
              if(app.documents.length != 0){
              
                  myDoc = app.activeDocument;
                  var pStyles = myDoc.allParagraphStyles;
              
                  var mystring = [], myids = [];
                  for (aa = 0; aa < pStyles.length; aa ++){
                      mystring[aa] = pStyles[aa].name;
                      myids[aa] = pStyles[aa].id;
                      if (pStyles[aa].parent.constructor.name == "ParagraphStyleGroup") mystring[aa]+=" ["+pStyles[aa].parent.name+"]";
                  }
              
                  // Create a list of paragraph styles
                  var list_of_paragraph_styles = [];
                  var all_paragraph_styles = [];
                  myDoc.paragraphStyles.everyItem().name;
              
                  for(var i = 0; i < myDoc.paragraphStyles.length; i++) {
                      list_of_paragraph_styles.push(myDoc.paragraphStyles[i].name);
                      all_paragraph_styles.push(myDoc.paragraphStyles[i]);
                  }
              
              
                  for(var i = 0; i < myDoc.paragraphStyleGroups.length; i++) {
                      for(var b = 0; b < myDoc.paragraphStyleGroups[i].paragraphStyles.length; b++) {
                          list_of_paragraph_styles.push(myDoc.paragraphStyleGroups[i].name+'/'+myDoc.paragraphStyleGroups[i].paragraphStyles[b].name);
                          all_paragraph_styles.push(myDoc.paragraphStyleGroups[i].paragraphStyles[b]);
                      }
                  }
              
                  var ln = app.selection.length ;
                  if (ln == 0) { // CS4-CC
                                  var _infos = infos._infos1 + infos._infos2 + infos._infos3 + infos._infos4;
                                  alert(_infos);
                  }
                  if (ln == 1) {
                      switch (app.selection[0].constructor.name){
                              case "Character": // Story
                              case "Word": // Story
                              case "Line": // Story
                              case "Paragraph": // Story
                              case "InsertionPoint": // Story
                              affichage(true) ;
                          break;
                              case "Text": // Story
                              case "TextColumn":
                              case "Story": 
                              case "TextFrame": // Spread
                              affichage(false) ;
                          break;
                              case "TextStyleRange": // Story
                              case "Rectangle":
                              alert(infos.alert1);
                          break;
                      }
                  }
              }
              
              
              function affichage(story) {
                  
              
                  if (story) {
                      var placedstory = app.selection[0].parentTextFrames[0].parentStory;
                      var pLn = placedstory.paragraphs.length;
                      var nextPara = -1;
                      for (var i = 0; i < pLn && nextPara == -1; i++) {
                          if (app.selection[0].paragraphs[0].contents == placedstory.paragraphs[i].contents)
                          nextPara = i+1;
                      }
                      if (nextPara == -1 || nextPara == pLn)  {
                          alert(infos.alert2);
                          exit();
                      }
                  }
                  
              
                  var mydialog = new Window("dialog", wScriptName + " v." + wScriptVersion);
                  with (mydialog) {
                      alignment = ["fill", "fill"];
                      
                      // options recherches
                      var searchPanel = add("panel", undefined, infos.panel1);
                      with(searchPanel){
                      alignment = ["fill", "fill"];
                      
                          var textCheckbox = add ("checkbox", undefined, infos.check1);
                          var groupeTexte = add("group");
                          with(groupeTexte) {
                              alignment = ["fill", "fill"];
                              alignChildren = "right";
                              groupeTexte.orientation = "row";
                              var stTxtTexte = groupeTexte.add("statictext");
                                  stTxtTexte.text = infos.stT1;
                                  stTxtTexte.helpTip = infos.stT2;
                              var stTxtTexte_e = groupeTexte.add( "edittext", undefined, "" );
                                  stTxtTexte_e.preferredSize = [260, 20];
                          }
                      
                          var GREPCheckbox = add ("checkbox", undefined, infos.check2);
                          var groupeGREP = add("group");
                          with(groupeGREP) {
                              alignment = ["fill", "fill"];
                              alignChildren = "right";
                              groupeGREP.orientation = "row";
                              var stTxtGREP = groupeGREP.add("statictext");
                                  stTxtGREP.text = infos.stT3;
                                  stTxtGREP.helpTip = infos.stT4;
                              var stTxtGREP_e = groupeGREP.add( "edittext", undefined, "" );
                                  stTxtGREP_e.preferredSize = [260, 20];
                          }
                          stTxtTexte_e.onChange = function() {
                              if (stTxtTexte_e != null) { 
                                  textCheckbox.value = true;
                                  GREPCheckbox.value = false;
                                  stTxtGREP_e.text = "";
                              }
                              else {
                                  textCheckbox.value = false;
                              }
                          }
                          stTxtGREP_e.onChange = function() {
                              if (stTxtTexte_e != null) { 
                                  GREPCheckbox.value = true;
                                  textCheckbox.value = false;
                                  stTxtTexte_e.text = "";
                              }
                              else {
                                  GREPCheckbox.value = false;
                              }
                          }
                          textCheckbox.onClick = function() {
                              if (textCheckbox.value == false) stTxtTexte_e.text = "";
                          }
                          GREPCheckbox.onClick = function() {
                              if (GREPCheckbox.value == false) stTxtGREP_e.text = "";
                          }
                      }
                      var overRideCheckbox = add ("checkbox", undefined, infos.check3);
                          overRideCheckbox.helpTip = infos.help1;
                      
                      // options styles de para
                      var stylesPanel = add("panel", undefined, infos.panel2);
                      with(stylesPanel){
                          alignChildren = "right";
                          var groupeGREP = add("group");
                          
                          
                      
                          var groupePara1 = add("group");
                          with(groupePara1) {
                              var para1_txt = add('statictext', undefined, infos.f1);
                              var find_first_paragraph = add('dropdownlist',undefined,undefined,{items:mystring});
                                  find_first_paragraph.helpTip = infos.f2;
                                  if (story) find_first_paragraph.selection = findid(app.selection[0].paragraphs[0].appliedParagraphStyle.id);
                                  else find_first_paragraph.selection = 0;
                          }
                          var groupePara2 = add("group");
                          with(groupePara2) {
                              var para2_txt = add('statictext', undefined, infos.f3);
                              var find_second_paragraph = add('dropdownlist',undefined,undefined,{items:mystring});
                                  find_second_paragraph.helpTip = infos.f2;
                                  if (story) find_second_paragraph.selection = findid(placedstory.paragraphs[nextPara].appliedParagraphStyle.id);
                                  else find_second_paragraph.selection = 0 ;
                          }
                          var groupePara3 = add("group");
                          with(groupePara3) {
                              var para3_txt = add('statictext', undefined, infos.f4);
                              var change_first_paragraph = add('dropdownlist',undefined,undefined,{items:mystring});
                                  change_first_paragraph.helpTip = infos.f2;
                                  change_first_paragraph.selection = 0;
                          }
                          var groupePara4 = add("group");
                          with(groupePara4) {
                              var para4_txt = add('statictext', undefined, infos.f5);
                              var change_second_paragraph = add('dropdownlist',undefined,undefined,{items:mystring});
                                  change_second_paragraph.helpTip = infos.f2;
                                  change_second_paragraph.selection = 0;
                          }
                      }
              
                          var okCancelGroup = add("group");
                          with (okCancelGroup) {
                              orientation = "row";
                              var okBtn = add("button", undefined, infos.ok, {name:"ok"});
                              var cancelBtn = add("button", undefined, infos.cancel, {name:"cancel"});
                          }
              
              
              
                  //*******************************************
                  }
                  // fenetre
                  var dialogResult = mydialog.show();
                  
                  // si OK :
                  if (dialogResult== 1) {
                      // Define paragraph styles
                      var find_first_paragraph = all_paragraph_styles[find_first_paragraph.selection.index];
                      var find_second_paragraph = all_paragraph_styles[find_second_paragraph.selection.index];
                      var change_first_paragraph = all_paragraph_styles[change_first_paragraph.selection.index];
                      var change_second_paragraph = all_paragraph_styles[change_second_paragraph.selection.index];
              
                      if (textCheckbox.value) {
                          // Set find grep preferences to find all paragraphs with the first selected paragraph style
                          app.findChangeTextOptions.includeFootnotes = false;
                          app.findChangeTextOptions.includeHiddenLayers = false;
                          app.findChangeTextOptions.includeLockedLayersForFind = false;
                          app.findChangeTextOptions.includeLockedStoriesForFind = false;
                          app.findChangeTextOptions.includeMasterPages = false;
              
                          app.findTextPreferences = NothingEnum.nothing;
                          app.findTextPreferences.appliedParagraphStyle = find_first_paragraph;
                          if (textCheckbox.value && stTxtTexte_e.text != null) {
                              app.findTextPreferences.findWhat = stTxtTexte_e.text;
                          } else {
                              app.findTextPreferences.findWhat = "";
                          }
                      }
                      if (GREPCheckbox.value || (!textCheckbox.value && !GREPCheckbox.value)) {
                          // Set find grep preferences to find all paragraphs with the first selected paragraph style
                          app.findChangeGrepOptions.includeFootnotes = false;
                          app.findChangeGrepOptions.includeHiddenLayers = false;
                          app.findChangeGrepOptions.includeLockedLayersForFind = false;
                          app.findChangeGrepOptions.includeLockedStoriesForFind = false;
                          app.findChangeGrepOptions.includeMasterPages = false;
              
                          app.findGrepPreferences = NothingEnum.nothing;
                          app.findGrepPreferences.appliedParagraphStyle = find_first_paragraph;
                          if (GREPCheckbox.value && stTxtGREP_e.text != null) {
                              app.findGrepPreferences.findWhat = stTxtGREP_e.text;
                          } else {
                              app.findGrepPreferences.findWhat = "$";
                          }
                      }
              
                      //Search the current story
                      if (story) var the_story = app.selection[0].parentStory;
                      else var the_story = app.selection[0];
                      if (textCheckbox.value) var found_paragraphs = the_story.findText();
                      if (GREPCheckbox.value || (!textCheckbox.value && !GREPCheckbox.value)) var found_paragraphs = the_story.findGrep();
              
                      var change_first_list = [];
                      var change_second_list = [];
              
                      // Loop through the paragraphs and create a list of words and mark them as index words
                      myCounter = 0;
                      do {
                          try {
                              // Create an object reference to the found paragraph and the next
                              var first_paragraph = found_paragraphs[myCounter].paragraphs.firstItem();
                              var next_paragraph = first_paragraph.paragraphs[-1].insertionPoints[-1].paragraphs[0];
              
                              // Check if the next paragraph is equal to the find_second_paragraph
                              if(next_paragraph.appliedParagraphStyle == find_second_paragraph) {
                                      change_first_list.push(first_paragraph);
                                      change_second_list.push(next_paragraph);
                              }
                          } catch(err) {}
                          myCounter++;
                      } while (myCounter < found_paragraphs.length); 
              
                      // Apply paragraph styles
                      if (overRideCheckbox.value) {
                          var defaultStyleName = "["+defaultStyle+"]"; 
                          noneStyle = app.activeDocument.characterStyles.item(defaultStyleName);
                          try {
                              basedOnNone = app.activeDocument.characterStyles.add({name:defaultStyle, basedOn:noneStyle});
                          } catch(e) {
                              basedOnNone = app.activeDocument.characterStyles.item(defaultStyle);
                          }
                          myCounter = 0;
                          if (change_first_list.length > 0 && change_second_list.length > 0 ) {
                              do {
                                  change_first_list[myCounter].appliedCharacterStyle = basedOnNone;
                                  change_first_list[myCounter].appliedParagraphStyle = change_first_paragraph;
                                  change_second_list[myCounter].appliedCharacterStyle = basedOnNone;
                                  change_second_list[myCounter].appliedParagraphStyle = change_second_paragraph;
                                  myCounter++;
                              } while (myCounter < change_first_list.length);
                          }
                          //myDoc.characterStyles.item("old style name").remove("new style name"); 
                          try { myDoc.characterStyles.item(infos.defStyle).remove(); } catch(e) {}
                      }
                      else {
                          myCounter = 0;
                          if (change_first_list.length > 0 && change_second_list.length > 0 ) {
                              do {
                                  change_first_list[myCounter].appliedParagraphStyle = change_first_paragraph;
                                  change_second_list[myCounter].appliedParagraphStyle = change_second_paragraph;
                                  myCounter++;
                              } while (myCounter < change_first_list.length);
                          }
                      }
                      
                      alert(myCounter + infos.alert3);
                  }
              }
              
              
              function findid(lid) {
                  for (var i = 0; i < myids.length; i++) {
                      if (myids[i] == lid)
                          return i;
                  }
                  return -1;
              }
              
              • 4. Re: Fixing *multiple* Paragraph Style combinations at once
                Wosven Level 1

                Here the second script.

                 

                I needed this one for long book generated from datas, where I need to correct multi-lines paragraphs styles.

                 

                Paragraphs changes can be stored in a text file (you need to create it at same level as the script — file name : listeRemplacements_x10.txt)

                The change list is named from the file name, and will be selected automatically (if exists), or can be choosen later from a menu.

                You can select which changes are applied, to apply clear overrides.

                You can dupplicate (by renaming) a list.

                 

                Just be carefull with styles changes order.

                 

                //DESCRIPTION: Multi-paragraphs' styles replacements
                
                /*
                    Fixing paragraph style combinations
                    Version: 1.2
                
                    Script original by Thomas Silkjær
                    http://indesigning.net/
                
                    version 2 (modernisation, fr, etc.)
                    
                    version multi x10 + memorisation
                    par Wosven
                
                Use/need a text file for saving parameters :
                Utilise un fichier texte pour mémoriser les paramètres :
                listeRemplacememnts_x10.txt
                
                ///////////////////////////////////////////////////////////////
                //  ATTENTION : BE CAREFULL WITH STYLE REPLACEMENT ORDER     //
                //  NOT REPLACING A STYLE REPLACED IN A PRECEDING REQUEST    //
                ///////////////////////////////////////////////////////////////
                //       ATTENTION : METTRE LES STYLES DANS L'ORDRE INVERSE  //
                //          POUR NE PAS REMPLACER LES STYLES REMPLACÉS       //
                ///////////////////////////////////////////////////////////////
                
                Use multi Ctrl+z (×2 by style replaced)
                
                Possibilité de retours arrières (ctrl-z) : 2 par styles remplacés, pas mieux (1 seul)
                => 1 remplacement + 1 clearOverrides
                */
                
                
                
                if (app.locale.toString() == "FRENCH_LOCALE") {
                
                    var infos = {
                        scrName:    "Remplace des styles de paragraphe x10", 
                        panel1 :     "Choix d'une liste enregistrée :",
                        stT1 :         'Remplacements mémorisés : ',
                        help1 :     "Listes mémorisées, laisser vide lors d'une création de liste\nla nouvelle liste aura le nom du document ouvert\net sera sélectionnée automatiquement",
                        paraB :     'Nom mémorisé / à mémoriser : ',
                        help2 :     "Si non vide, sert de nom d'enregistrement\rutile pour duppliquer une liste",
                        panel2 :     "Créer une liste de remplacements de styles :",
                        para0 :     'ATTENTION : METTRE LES STYLES DANS L’ORDRE INVERSE POUR NE PAS REMPLACER LES STYLES REMPLACÉS',
                        help3 :     "Exemple ordre de remplacements : \n01. Rempl. Style_5 par Style_2\n02. Rempl. Style_1 par Style_5",
                        by :         'par :',
                        list :         "Liste des styles de paragraphe disponibles\r",
                        checkH :     "Sera appliqué ou non\r",
                        para0 :     '. Remplacer :',
                        appl0 :     "Appl. ",
                        nb01 :         '01',
                        nb02 :         '02',
                        nb03 :         '03',
                        nb04 :         '04',
                        nb05 :         '05',
                        nb06 :         '06',
                        nb07 :         '07',
                        nb08 :         '08',
                        nb09 :         '09',
                        nb10 :         '10',
                        help4 :     "Possibilité de retours arrières (ctrl-z) : \r2 par styles remplacés, pas mieux \r=> (1 remplacement + 1 clearOverrides) / style",
                        check1 :    "Effacer les remplacements",
                        help5 :     "Supprime les modifications ne correspondant pas \naux styles (para & cara)",
                        check2 :     "Mémoriser la liste",
                        help6 :     "La liste réutilisable apparaîtra dans le menu du haut",
                        ok :         "Valider",
                        cancel :    "Annuler",
                        txt :         "Nombre de remplacements :\n",
                        alertErr1 :        "Erreur de sélection",
                        alert1 :        "Sélectionnez du texte",
                        alertErr2 :        "Erreur d'application",
                        alert2 :         "repl. x10 : ",
                        alertErr3 :        "Erreur fichier",
                        alert3 :         "Choisir le fichier contenant la liste des styles.",
                        alertFinale :    "Résultats"
                    };
                }
                else {
                
                    var infos = {
                        scrName:    "Change paragraphs styles x10", 
                        panel1 :     "Select a list of parameters:",
                        stT1 :         'Saved Replacements: ',
                        help1 :     "Savedlists, keep blank for creating a list\nthe new list will be named from open document's name\nand will be selected automatically",
                        paraB :     'Saved name / to save: ',
                        help2 :     "If not blank, is used as name\ruse this for dupplicating a list",
                        panel2 :     "Create a styles' replacements list:",
                        paraH :     'BE CAREFULL WITH REPLACEMENT ORDER',
                        help3 :     "Order example: \n01. Repl. Style_5 by Style_2\n02. Repl. Style_1 by Style_5",
                        by :         'by:',
                        list :         "Paragraphs styles list available\r",
                        checkH :     "To apply or not\r",
                        para0 :     '. Replace:',
                        appl0 :     "Apply ",
                        nb01 :         '01',
                        nb02 :         '02',
                        nb03 :         '03',
                        nb04 :         '04',
                        nb05 :         '05',
                        nb06 :         '06',
                        nb07 :         '07',
                        nb08 :         '08',
                        nb09 :         '09',
                        nb10 :         '10',
                        help4 :     "Possible (ctrl-z) : \r2 by replaced styles, not better \r=> (1 replacement + 1 clearOverrides) / style",
                        check1 :    "Erase replacements",
                        help5 :     "Delete overrides (para & cara)",
                        check2 :     "Save the list",
                        help6 :     "The saved list will appear in the menu above",
                        ok :         "Ok",
                        cancel :    "Cancel",
                        txt :         "Number of replacements:\n",
                        alertErr1 :        "Selection error",
                        alert1 :        "Select some text",
                        alertErr2 :        "Apply error",
                        alert2 :         "repl. x10: ",
                        alertErr3 :        "File error",
                        alert3 :         "Select the text file which contains the styles list.",
                        alertFinale :    "Results"
                    };
                
                }
                
                
                
                //Allez zou !
                main_a_la_pate();
                
                // Make the dialog box for selecting the paragraph styles
                function main_a_la_pate() {
                    var txtListe = "listeRemplacements_x10.txt";
                    var myListeFile = File(myFindFile(txtListe));
                    var listeEnregistrees = new ListeDocStyles();
                    var listeNoms = [];
                    var the_document = app.documents.item(0);
                
                
                    // Create a list of paragraph styles
                    var list_of_paragraph_styles = []; // item list
                    var all_paragraph_styles = [];
                    listerTxt();
                    the_document.paragraphStyles.everyItem().name;
                
                    for(var i = 0; i < the_document.paragraphStyles.length; i++) {
                        list_of_paragraph_styles.push(the_document.paragraphStyles[i].name);
                        all_paragraph_styles.push(the_document.paragraphStyles[i]);
                    }
                
                
                    for(var i = 0; i < the_document.paragraphStyleGroups.length; i++) {
                        for(var b = 0; b < the_document.paragraphStyleGroups[i].paragraphStyles.length; b++) {
                            list_of_paragraph_styles.push(the_document.paragraphStyleGroups[i].name+'/'+the_document.paragraphStyleGroups[i].paragraphStyles[b].name);
                            all_paragraph_styles.push(the_document.paragraphStyleGroups[i].paragraphStyles[b]);
                        }
                    }
                
                
                    var the_dialog = new Window("dialog", infos.scrName);
                    with (the_dialog) {
                        alignment = ["fill", "fill"];
                
                        var test1 = listeEnregistrees.findDoc(app.activeDocument.name);
                        var maListe = (test1 != -1) ? listeEnregistrees.docs[test1] : false ;
                        var choixPanel = add("panel", undefined, infos.panel1);
                        with(choixPanel){
                            alignChildren = "right";
                
                            var groupeParaA = add("group");
                            with(groupeParaA) {
                                var paraA_txt = add('statictext', undefined, infos.stT1);
                                var choix_memo = add('dropdownlist',undefined,undefined,{items:listeNoms});
                                    choix_memo.helpTip = infos.help1;
                                    if (maListe != false) choix_memo.selection = test1;
                                    choix_memo.onChange = function() {
                                    // alert(choix_memo.selection.index) ;
                                    //alert(listeEnregistrees.docs[choix_memo.selection.index].nom);
                                    stTxtTexte_e.text = choix_memo.selection;
                
                                    find_first_paragraph.selection = getPara_idx(list_of_paragraph_styles, listeEnregistrees.docs[choix_memo.selection.index].styles.s01[1]) ;
                                    replace_first_paragraph.selection = getPara_idx(list_of_paragraph_styles, listeEnregistrees.docs[choix_memo.selection.index].styles.s01[2]) ;
                                    checkbox_1.value = listeEnregistrees.docs[choix_memo.selection.index].styles.s01[0];
                
                                    find_second_paragraph.selection = getPara_idx(list_of_paragraph_styles, listeEnregistrees.docs[choix_memo.selection.index].styles.s02[1]) ;
                                    replace_second_paragraph.selection = getPara_idx(list_of_paragraph_styles, listeEnregistrees.docs[choix_memo.selection.index].styles.s02[2]) ;
                                    checkbox_2.value = listeEnregistrees.docs[choix_memo.selection.index].styles.s02[0];
                
                                    find_third_paragraph.selection = getPara_idx(list_of_paragraph_styles, listeEnregistrees.docs[choix_memo.selection.index].styles.s03[1]) ;
                                    replace_third_paragraph.selection = getPara_idx(list_of_paragraph_styles, listeEnregistrees.docs[choix_memo.selection.index].styles.s03[2]) ;
                                    checkbox_3.value = listeEnregistrees.docs[choix_memo.selection.index].styles.s03[0];
                
                                    find_4th_paragraph.selection = getPara_idx(list_of_paragraph_styles, listeEnregistrees.docs[choix_memo.selection.index].styles.s04[1]) ;
                                    replace_4th_paragraph.selection = getPara_idx(list_of_paragraph_styles, listeEnregistrees.docs[choix_memo.selection.index].styles.s04[2]) ;
                                    checkbox_4.value = listeEnregistrees.docs[choix_memo.selection.index].styles.s04[0];
                
                                    find_5th_paragraph.selection = getPara_idx(list_of_paragraph_styles, listeEnregistrees.docs[choix_memo.selection.index].styles.s05[1]) ;
                                    replace_5th_paragraph.selection = getPara_idx(list_of_paragraph_styles, listeEnregistrees.docs[choix_memo.selection.index].styles.s05[2]) ;
                                    checkbox_5.value = listeEnregistrees.docs[choix_memo.selection.index].styles.s05[0];
                
                                    find_6th_paragraph.selection = getPara_idx(list_of_paragraph_styles, listeEnregistrees.docs[choix_memo.selection.index].styles.s06[1]) ;
                                    replace_6th_paragraph.selection = getPara_idx(list_of_paragraph_styles, listeEnregistrees.docs[choix_memo.selection.index].styles.s06[2]) ;
                                    checkbox_6.value = listeEnregistrees.docs[choix_memo.selection.index].styles.s06[0];
                
                                    find_7th_paragraph.selection = getPara_idx(list_of_paragraph_styles, listeEnregistrees.docs[choix_memo.selection.index].styles.s07[1]);
                                    replace_7th_paragraph.selection = getPara_idx(list_of_paragraph_styles, listeEnregistrees.docs[choix_memo.selection.index].styles.s07[2]);
                                    checkbox_7.value = listeEnregistrees.docs[choix_memo.selection.index].styles.s07[0];
                
                                    find_8th_paragraph.selection = getPara_idx(list_of_paragraph_styles, listeEnregistrees.docs[choix_memo.selection.index].styles.s08[1]) ;
                                    replace_8th_paragraph.selection = getPara_idx(list_of_paragraph_styles, listeEnregistrees.docs[choix_memo.selection.index].styles.s08[2]) ;
                                    checkbox_8.value = listeEnregistrees.docs[choix_memo.selection.index].styles.s08[0];
                
                                    find_9th_paragraph.selection = getPara_idx(list_of_paragraph_styles, listeEnregistrees.docs[choix_memo.selection.index].styles.s09[1]) ;
                                    replace_9th_paragraph.selection = getPara_idx(list_of_paragraph_styles, listeEnregistrees.docs[choix_memo.selection.index].styles.s09[2]);
                                    checkbox_9.value = listeEnregistrees.docs[choix_memo.selection.index].styles.s09[0];
                
                                    find_10th_paragraph.selection = getPara_idx(list_of_paragraph_styles, listeEnregistrees.docs[choix_memo.selection.index].styles.s10[1]) ;
                                    replace_10th_paragraph.selection = getPara_idx(list_of_paragraph_styles, listeEnregistrees.docs[choix_memo.selection.index].styles.s10[2]) ;
                                    checkbox_10.value = listeEnregistrees.docs[choix_memo.selection.index].styles.s10[0];
                
                                }
                            }
                            var groupeParaB = add("group");
                            with(groupeParaB) {
                                var paraB_txt = add('statictext', undefined, infos.paraB);
                                var stTxtTexte_e = add( "edittext", undefined, (maListe != false) ? maListe.nom : "" );
                                    stTxtTexte_e.preferredSize = [360, 20];
                                    stTxtTexte_e.helpTip = infos.help2;
                            }
                        }
                
                        var stylesPanel = add("panel", undefined, infos.panel2);
                
                        with(stylesPanel){
                            alignChildren = "right";
                
                            var groupePara0 = add("group");
                            with(groupePara0) {
                                var para0_txt = add('statictext', undefined, infos.paraH);
                                    para0_txt.helpTip = infos.help3;
                            }
                            var groupePara1 = add("group");
                            with(groupePara1) {
                                var para1_txt = add('statictext', undefined, infos.nb01+infos.para0);
                                    para1_txt.helpTip = infos.help4;
                                var find_first_paragraph = add('dropdownlist',undefined,undefined,{items:list_of_paragraph_styles});
                
                                var para1b_txt = add('statictext', undefined, infos.by);
                                var replace_first_paragraph = add('dropdownlist',undefined,undefined,{items:list_of_paragraph_styles});
                                    replace_first_paragraph.helpTip = infos.list;
                                var checkbox_1 = add ("checkbox", undefined, infos.appl0+infos.nb01);
                                    checkbox_1.helpTip = infos.checkH;
                                if (maListe != false) {
                                    find_first_paragraph.selection = getPara_idx(list_of_paragraph_styles, maListe.styles.s01[1]) ;
                                    replace_first_paragraph.selection = getPara_idx(list_of_paragraph_styles, maListe.styles.s01[2]) ;
                                    checkbox_1.value = maListe.styles.s01[0];
                                }
                                else {
                                    find_first_paragraph.selection = 0;
                                    replace_first_paragraph.selection = 0;
                                    checkbox_1.value = false;
                                }
                            }
                            var groupePara2 = add("group");
                            with(groupePara2) {
                                var para2_txt = add('statictext', undefined, infos.nb02+infos.para0);
                                 var find_second_paragraph = add('dropdownlist',undefined,undefined,{items:list_of_paragraph_styles});
                
                                var para2b_txt = add('statictext', undefined, infos.by);
                                var replace_second_paragraph = add('dropdownlist',undefined,undefined,{items:list_of_paragraph_styles});
                                    replace_second_paragraph.helpTip = infos.list;
                                var checkbox_2 = add ("checkbox", undefined, infos.appl0+infos.nb02);
                                if (maListe != false) {
                                    find_second_paragraph.selection = getPara_idx(list_of_paragraph_styles, maListe.styles.s02[1]) ;
                                    replace_second_paragraph.selection = getPara_idx(list_of_paragraph_styles, maListe.styles.s02[2]) ;
                                    checkbox_2.value = maListe.styles.s02[0];
                                }
                                else {
                                    find_second_paragraph.selection = 0;
                                    replace_second_paragraph.selection = 0;
                                    checkbox_2.value = false;
                                }
                            }
                            var groupePara3 = add("group");
                            with(groupePara3) {
                                var para3_txt = add('statictext', undefined, infos.nb03+infos.para0);
                                var find_third_paragraph = add('dropdownlist',undefined,undefined,{items:list_of_paragraph_styles});
                
                                var para3b_txt = add('statictext', undefined, infos.by);
                                var replace_third_paragraph = add('dropdownlist',undefined,undefined,{items:list_of_paragraph_styles});
                                    replace_third_paragraph.helpTip = infos.list;
                                var checkbox_3 = add ("checkbox", undefined, infos.appl0+infos.nb03);
                                if (maListe != false) {
                                    find_third_paragraph.selection = getPara_idx(list_of_paragraph_styles, maListe.styles.s03[1]) ;
                                    replace_third_paragraph.selection = getPara_idx(list_of_paragraph_styles, maListe.styles.s03[2]) ;
                                    checkbox_3.value = maListe.styles.s03[0];
                                }
                                else {
                                    find_third_paragraph.selection = 0;
                                    replace_third_paragraph.selection = 0;
                                    checkbox_3.value = false;
                                }
                            }
                            var groupePara4 = add("group");
                            with(groupePara4) {
                                var para4_txt = add('statictext', undefined, infos.nb04+infos.para0);
                                var find_4th_paragraph = add('dropdownlist',undefined,undefined,{items:list_of_paragraph_styles});
                
                                var para4b_txt = add('statictext', undefined, infos.by);
                                var replace_4th_paragraph = add('dropdownlist',undefined,undefined,{items:list_of_paragraph_styles});
                                    replace_4th_paragraph.helpTip = infos.list;
                                var checkbox_4 = add ("checkbox", undefined, infos.appl0+infos.nb04);
                                if (maListe != false) {
                                    find_4th_paragraph.selection = getPara_idx(list_of_paragraph_styles, maListe.styles.s04[1]) ;
                                    replace_4th_paragraph.selection = getPara_idx(list_of_paragraph_styles, maListe.styles.s04[2]) ;
                                    checkbox_4.value = maListe.styles.s04[0];
                                }
                                else {
                                    find_4th_paragraph.selection = 0;
                                    replace_4th_paragraph.selection =  0;
                                    checkbox_4.value = false;
                                }
                            }
                            var groupePara5 = add("group");
                            with(groupePara5) {
                                var para5_txt = add('statictext', undefined, infos.nb05+infos.para0);
                                var find_5th_paragraph = add('dropdownlist',undefined,undefined,{items:list_of_paragraph_styles});
                
                                var para5b_txt = add('statictext', undefined, infos.by);
                                var replace_5th_paragraph = add('dropdownlist',undefined,undefined,{items:list_of_paragraph_styles});
                                    replace_5th_paragraph.helpTip = infos.list;
                                var checkbox_5 = add ("checkbox", undefined, infos.appl0+infos.nb05);
                                if (maListe != false) {
                                    find_5th_paragraph.selection = getPara_idx(list_of_paragraph_styles, maListe.styles.s05[1]) ;
                                    replace_5th_paragraph.selection = getPara_idx(list_of_paragraph_styles, maListe.styles.s05[2]) ;
                                    checkbox_5.value = maListe.styles.s05[0];
                                }
                                else {
                                    find_5th_paragraph.selection = 0;
                                    replace_5th_paragraph.selection = 0;
                                    checkbox_5.value = false;
                                }
                            }
                            var groupePara6 = add("group");
                            with(groupePara6) {
                                var para6_txt = add('statictext', undefined, infos.nb06+infos.para0);
                                var find_6th_paragraph = add('dropdownlist',undefined,undefined,{items:list_of_paragraph_styles});
                
                                var para6b_txt = add('statictext', undefined, infos.by);
                                var replace_6th_paragraph = add('dropdownlist',undefined,undefined,{items:list_of_paragraph_styles});
                                    replace_6th_paragraph.helpTip = infos.list;
                                var checkbox_6 = add ("checkbox", undefined, infos.appl0+infos.nb06);
                                if (maListe != false) {
                                    find_6th_paragraph.selection = getPara_idx(list_of_paragraph_styles, maListe.styles.s06[1]) ;
                                    replace_6th_paragraph.selection = getPara_idx(list_of_paragraph_styles, maListe.styles.s06[2]) ;
                                    checkbox_6.value = maListe.styles.s06[0];
                                }
                                else {
                                    find_6th_paragraph.selection = 0;
                                    replace_6th_paragraph.selection = 0;
                                    checkbox_6.value = false;
                                }
                            }
                            var groupePara7 = add("group");
                            with(groupePara7) {
                                var para7_txt = add('statictext', undefined, infos.nb07+infos.para0);
                                var find_7th_paragraph = add('dropdownlist',undefined,undefined,{items:list_of_paragraph_styles});
                
                                var para7b_txt = add('statictext', undefined, infos.by);
                                var replace_7th_paragraph = add('dropdownlist',undefined,undefined,{items:list_of_paragraph_styles});
                                    replace_7th_paragraph.helpTip = infos.list;
                                var checkbox_7 = add ("checkbox", undefined, infos.appl0+infos.nb07);
                                if (maListe != false) {
                                    find_7th_paragraph.selection = getPara_idx(list_of_paragraph_styles, maListe.styles.s07[1]);
                                    replace_7th_paragraph.selection = getPara_idx(list_of_paragraph_styles, maListe.styles.s07[2]);
                                    checkbox_7.value = maListe.styles.s07[0];
                                }
                                else {
                                    find_7th_paragraph.selection = 0;
                                    replace_7th_paragraph.selection = 0;
                                    checkbox_7.value = false;
                                }
                            }
                            var groupePara8 = add("group");
                            with(groupePara8) {
                                var para8_txt = add('statictext', undefined, infos.nb08+infos.para0);
                                var find_8th_paragraph = add('dropdownlist',undefined,undefined,{items:list_of_paragraph_styles});
                
                                var para8b_txt = add('statictext', undefined, infos.by);
                                var replace_8th_paragraph = add('dropdownlist',undefined,undefined,{items:list_of_paragraph_styles});
                                    replace_8th_paragraph.helpTip = infos.list;
                                var checkbox_8 = add ("checkbox", undefined, infos.appl0+infos.nb08);
                                if (maListe != false) {
                                    find_8th_paragraph.selection = getPara_idx(list_of_paragraph_styles, maListe.styles.s08[1]) ;
                                    replace_8th_paragraph.selection = getPara_idx(list_of_paragraph_styles, maListe.styles.s08[2]) ;
                                    checkbox_8.value = maListe.styles.s08[0];
                                }
                                else {
                                    find_8th_paragraph.selection = 0;
                                    replace_8th_paragraph.selection = 0;
                                    checkbox_8.value = false;
                                }
                            }
                            var groupePara9 = add("group");
                            with(groupePara9) {
                                var para9_txt = add('statictext', undefined, infos.nb09+infos.para0);
                                var find_9th_paragraph = add('dropdownlist',undefined,undefined,{items:list_of_paragraph_styles});
                
                                var para9b_txt = add('statictext', undefined, infos.by);
                                var replace_9th_paragraph = add('dropdownlist',undefined,undefined,{items:list_of_paragraph_styles});
                                    replace_9th_paragraph.helpTip = infos.list;
                                var checkbox_9 = add ("checkbox", undefined, infos.appl0+infos.nb09);
                                if (maListe != false) {
                                    find_9th_paragraph.selection = getPara_idx(list_of_paragraph_styles, maListe.styles.s09[1]) ;
                                    replace_9th_paragraph.selection = getPara_idx(list_of_paragraph_styles, maListe.styles.s09[2]);
                                    checkbox_9.value = maListe.styles.s09[0];
                                }
                                else {
                                    find_9th_paragraph.selection = 0;
                                    replace_9th_paragraph.selection = 0;
                                    checkbox_9.value = false;
                                }
                            }
                            var groupePara10 = add("group");
                            with(groupePara10) {
                                var para10_txt = add('statictext', undefined, infos.nb10+infos.para0);
                                var find_10th_paragraph = add('dropdownlist',undefined,undefined,{items:list_of_paragraph_styles});
                
                                var para10b_txt = add('statictext', undefined, infos.by);
                                var replace_10th_paragraph = add('dropdownlist',undefined,undefined,{items:list_of_paragraph_styles});
                                    replace_10th_paragraph.helpTip = infos.list;
                                var checkbox_10 = add ("checkbox", undefined, infos.appl0+infos.nb10);
                                if (maListe != false) {
                                    find_10th_paragraph.selection = getPara_idx(list_of_paragraph_styles, maListe.styles.s10[1]) ;
                                    replace_10th_paragraph.selection = getPara_idx(list_of_paragraph_styles, maListe.styles.s10[2]) ;
                                    checkbox_10.value = maListe.styles.s10[0];
                                }
                                else {
                                    find_10th_paragraph.selection = 0;
                                    replace_10th_paragraph.selection = 0;
                                    checkbox_10.value = false;
                                }
                            }
                            var overCheckbox = add ("checkbox", undefined, infos.check1);
                                overCheckbox.helpTip = infos.help5;
                                if (maListe != false) {
                                    overCheckbox.value = (maListe.over == false) ? false : true ;
                                }
                                else {
                                    overCheckbox.value = false;
                            }
                        }
                
                            var okCancelGroup = add("group");
                            with (okCancelGroup) {
                                orientation = "row";
                                var memCheckbox = add ("checkbox", undefined, infos.check2);
                                    memCheckbox.helpTip = infos.help6;
                                var okBtn = add("button", undefined, infos.ok, {name:"ok"});
                                var cancelBtn = add("button", undefined, infos.cancel, {name:"cancel"});
                            }
                
                        var dialogResult = the_dialog.show();
                    }
                    if (dialogResult== 1) {
                
                        if (memCheckbox.value) {
                            //    alert( typeof maListe.over + "\n" + maListe.over + "\n" + overCheckbox.value);
                            // on enregistre la liste dans le fichier txt
                        //    alert(find_first_paragraph.selection.index + "\n" + find_first_paragraph.selection + "\n" + find_first_paragraph.selection.text)
                                var thisStyles = new Styles([ checkbox_1.value, find_first_paragraph.selection.text,     replace_first_paragraph.selection.text],
                                                        [ checkbox_2.value, find_second_paragraph.selection.text,     replace_second_paragraph.selection.text],
                                                        [ checkbox_3.value, find_third_paragraph.selection.text,     replace_third_paragraph.selection.text],
                                                        [ checkbox_4.value, find_4th_paragraph.selection.text,     replace_4th_paragraph.selection.text],
                                                        [ checkbox_5.value, find_5th_paragraph.selection.text,     replace_5th_paragraph.selection.text],
                                                        [ checkbox_6.value, find_6th_paragraph.selection.text,     replace_6th_paragraph.selection.text],
                                                        [ checkbox_7.value, find_7th_paragraph.selection.text,     replace_7th_paragraph.selection.text],
                                                        [ checkbox_8.value, find_8th_paragraph.selection.text,     replace_8th_paragraph.selection.text],
                                                        [ checkbox_9.value, find_9th_paragraph.selection.text,        replace_9th_paragraph.selection.text],
                                                        [checkbox_10.value, find_10th_paragraph.selection.text,     replace_10th_paragraph.selection.text]);
                            var docName = (stTxtTexte_e.text !== "") ? stTxtTexte_e.text : app.activeDocument.name ;
                            var thisDoc = new DocumentInfos(docName, thisStyles, overCheckbox.value);
                            var donnees = exportList2Txt(listeEnregistrees);
                            var test1 = listeEnregistrees.findDoc(thisDoc.nom);
                            if (test1 != -1) listeEnregistrees.modDoc(thisDoc, test1);
                            else listeEnregistrees.addDoc(thisDoc);
                
                            var donnees = exportList2Txt(listeEnregistrees);
                            if (donnees) writeToFile(txtListe, donnees, "");
                        }
                        else {
                            try {
                                var txt = infos.txt;
                                // Define paragraph styles
                                if (app.selection.length == 0) {    
                                    alert(infos.alert1, infos.alertErr1);
                                }
                                else {
                                    var test0 = false;
                                    switch (app.selection[0].constructor.name){
                                            case "Character":
                                            case "Word":
                                            case "Line":
                                            case "Text":
                                            case "Paragraph":
                                            case "TextColumn":
                                            case "TextStyleRange":
                                            case "Story": // ??? pas évident
                                            test0 = true; 
                                        break;
                                            case "InsertionPoint":
                                            case "TextFrame":
                                            case "Rectangle":
                                            alert(infos.alert1, infos.alertErr1);
                                        break;
                                        default: alert(infos.alert1, infos.alertErr1);
                                        break;
                                    }
                                    if (test0) {
                                        if (checkbox_1.value) {
                                            var find_first_paragraph =         all_paragraph_styles[find_first_paragraph.selection.index];
                                            var replace_first_paragraph =     all_paragraph_styles[replace_first_paragraph.selection.index];
                                                txt += "\n"+infos.nb01+" : " +  remplaceStyles(find_first_paragraph, replace_first_paragraph) ;
                                        }
                                        if (checkbox_2.value) {
                                            var find_second_paragraph =     all_paragraph_styles[find_second_paragraph.selection.index];
                                            var replace_second_paragraph =     all_paragraph_styles[replace_second_paragraph.selection.index];
                                                txt += "\n"+infos.nb02+" : " +  remplaceStyles(find_second_paragraph, replace_second_paragraph) ;
                                        }
                                        if (checkbox_3.value) {
                                            var find_third_paragraph =         all_paragraph_styles[find_third_paragraph.selection.index];
                                            var replace_third_paragraph =     all_paragraph_styles[replace_third_paragraph.selection.index];
                                                txt += "\n"+infos.nb03+" : " +  remplaceStyles(find_third_paragraph, replace_third_paragraph) ;
                                        }
                                        if (checkbox_4.value) {
                                            var find_4th_paragraph =         all_paragraph_styles[find_4th_paragraph.selection.index];
                                            var replace_4th_paragraph =     all_paragraph_styles[replace_4th_paragraph.selection.index];
                                                txt += "\n"+infos.nb04+" : " +  remplaceStyles(find_4th_paragraph, replace_4th_paragraph) ;
                                        }
                                        if (checkbox_5.value) {
                                            var find_5th_paragraph =         all_paragraph_styles[find_5th_paragraph.selection.index];
                                            var replace_5th_paragraph =     all_paragraph_styles[replace_5th_paragraph.selection.index];
                                                txt += "\n"+infos.nb05+" : " +  remplaceStyles(find_5th_paragraph, replace_5th_paragraph) ;
                                        }
                                        if (checkbox_6.value) {
                                            var find_6th_paragraph =         all_paragraph_styles[find_6th_paragraph.selection.index];
                                            var replace_6th_paragraph =     all_paragraph_styles[replace_6th_paragraph.selection.index];
                                                txt += "\n"+infos.nb06+" : " +  remplaceStyles(find_6th_paragraph, replace_6th_paragraph) ;
                                        }
                                        if (checkbox_7.value) {
                                            var find_7th_paragraph =         all_paragraph_styles[find_7th_paragraph.selection.index];
                                            var replace_7th_paragraph =     all_paragraph_styles[replace_7th_paragraph.selection.index];
                                                txt += "\n"+infos.nb07+" : " +  remplaceStyles(find_7th_paragraph, replace_7th_paragraph) ;
                                        }
                                        if (checkbox_8.value) {
                                            var find_8th_paragraph =         all_paragraph_styles[find_8th_paragraph.selection.index];
                                            var replace_8th_paragraph =     all_paragraph_styles[replace_8th_paragraph.selection.index];
                                                txt += "\n"+infos.nb08+" : " +  remplaceStyles(find_8th_paragraph, replace_8th_paragraph) ;
                                        }
                                        if (checkbox_9.value) {
                                            var find_9th_paragraph =         all_paragraph_styles[find_9th_paragraph.selection.index];
                                            var replace_9th_paragraph =     all_paragraph_styles[replace_9th_paragraph.selection.index];
                                                txt += "\n"+infos.nb09+" : " +  remplaceStyles(find_9th_paragraph, replace_9th_paragraph) ;
                                        }
                                        if (checkbox_10.value) {
                                            var find_10th_paragraph =         all_paragraph_styles[find_10th_paragraph.selection.index];
                                            var replace_10th_paragraph =     all_paragraph_styles[replace_10th_paragraph.selection.index];
                                                txt += "\n"+infos.nb10+" : " +  remplaceStyles(find_10th_paragraph, replace_10th_paragraph) ;
                                        }
                                        alert(txt, infos.alertFinale);
                                    }
                                }
                            } catch(e) { alert(infos.alert2 + e, infos.alertErr2);}
                        }
                
                        function remplaceStyles(findS, replaceS) {
                
                            // Set find grep preferences to find all paragraphs with the first selected paragraph style
                            app.findChangeGrepOptions.includeFootnotes = false;
                            app.findChangeGrepOptions.includeHiddenLayers = false;
                            app.findChangeGrepOptions.includeLockedLayersForFind = false;
                            app.findChangeGrepOptions.includeLockedStoriesForFind = false;
                            app.findChangeGrepOptions.includeMasterPages = false;
                
                            app.findGrepPreferences = NothingEnum.nothing;
                            app.findGrepPreferences.appliedParagraphStyle = findS;
                            app.findGrepPreferences.findWhat = ""; // $
                            app.changeGrepPreferences = NothingEnum.nothing;
                            app.changeGrepPreferences.changeTo = "";
                            app.changeGrepPreferences.appliedParagraphStyle = replaceS;
                
                            //Search the current story
                        //    var the_story = app.selection[0].parentStory;
                        //    try {
                                var found_paragraphs = app.selection[0].findGrep();
                                if (found_paragraphs.length > 0) {
                                    app.selection[0].changeGrep();
                                    if (overCheckbox.value)  
                                        app.selection[0].clearOverrides();
                                }
                        //    } catch(e) { alert("remplaceStyles : " + e);}
                            return (found_paragraphs.length);
                        }
                    }
                
                
                    ///////////////////// FONCTIONS SUPP //////////////////////////////////////
                
                    function myFindFile(myFilePath) {
                        var myScriptFile = myGetScriptPath();
                            myScriptFile = File(myScriptFile);
                        var myScriptFolder = myScriptFile.path;
                        myFilePath = myScriptFolder + "/" + myFilePath;
                        if(File(myFilePath).exists == false) {
                            //Display a dialog.
                            myFilePath = File.openDialog(infos.alert3, infos.alertErr3);
                        }
                        // else alert("ok");
                        return myFilePath;
                    }
                    function myGetScriptPath() {
                        try {
                            myFile = app.activeScript;
                        }
                        catch(myError){
                            myFile = myError.fileName;
                        }
                        return myFile;
                    }
                    function writeToFile(zeFile, myText, rewriteAll) {
                        var myScriptFile = myGetScriptPath();
                            myScriptFile = File(myScriptFile);
                        var myScriptFolder = myScriptFile.path;
                        var myFile = new File(myScriptFolder + "/"  + zeFile);
                        if ( myFile.exists && rewriteAll == undefined) {
                            myFile.open("e");
                            myFile.seek(0, 2);
                        }
                        else {
                            myFile.open("w");
                            //myText = nTest + "\n" + myText;
                        }
                        myFile.write(myText);
                        myFile.close();
                    }
                
                    // retourne la clef si obj est dans le tableau, sinon -1
                    // tester avec indexOf() ==> ne marche pas
                    function getPara_idx(arr, obj) {
                        for (var a = 0; a < arr.length; a++) {
                            if (arr[a] == obj) return a;
                        }
                        return 0; // liste item obligatoirement positive
                    }
                    ///////////////////////// FONCTIONS TEXTES //////////////////////
                
                
                    function exportList2Txt(obj){
                
                        if (obj.dlength > 0) {
                            var txt = "";
                            for (var i = 0; i < obj.dlength; i++){
                                txt += obj.docs[i].toSource() + "\n";
                            }
                            return txt;
                        }
                        return false;
                    }
                
                
                    /* ////////////////////
                    Donnees :
                    nom document
                    find_01
                    repl_01
                
                    */
                    function listerTxt() {
                        // Open the file for reading
                        //myListeFile.open("r");
                        myListeFile.open("r");
                        var texte = myListeFile.read();
                        var lignes = texte.split("\n");
                        listeEnregistrees = new ListeDocStyles();
                
                        for (var l = 0; l < lignes.length; l++) {
                
                            // on regarde la premiere lettre :
                            if (lignes[l] !== "" && lignes[l][0] == "(") {
                
                                var sousLn = lignes[l];
                                var docInfos = eval(lignes[l]);
                                var test1 = listeEnregistrees.findDoc(docInfos.nom);
                                if (test1 != -1) 
                                    listeEnregistrees.modDoc(docInfos, test1);
                                else {
                                    listeEnregistrees.addDoc(docInfos);
                                    listeNoms.push(docInfos.nom);
                                }
                            }
                        } // for
                    }
                
                
                
                    /////////////////////// OBJETS /////////////////////////
                
                
                    function ListeDocStyles() {
                        this.docs = [];
                        this.dlength = 0;
                
                        this.addDoc = addDoc;
                        this.modDoc = modDoc;
                        this.findDoc = findDoc;
                
                        function addDoc(doc) {
                            this.docs.push(doc);
                            this.dlength++;
                        }
                        function modDoc(doc, id) {
                            this.docs[id] = doc;
                        }
                        function findDoc(n) {
                            for (var i = 0; i < this.dlength; i++) {
                                if (this.docs[i].nom === n) 
                                    return i;
                            }
                            return -1;
                        }
                    }
                
                    function DocumentInfos(nom, styles, over) {
                        this.nom = nom;
                        this.styles = styles;
                        this.over = over;
                    }
                    // true/false = Appl.
                    // s01 = [true, f1, r1];
                    function Styles(s01, s02, s03, s04, s05, s06, s07, s08, s09, s10) {
                        this.s01 = s01;
                        this.s02 = s02;
                        this.s03 = s03;
                        this.s04 = s04;
                        this.s05 = s05;
                        this.s06 = s06;
                        this.s07 = s07;
                        this.s08 = s08;
                        this.s09 = s09;
                        this.s10 = s10;
                    }
                } // main
                
                1 person found this helpful
                • 5. Re: Fixing *multiple* Paragraph Style combinations at once
                  rndlm Level 1

                  Wow, that's a really simple solution, thanks!

                  Now I can build a full replacement script without having to wonder if certain styles are present in the document.

                  • 6. Re: Fixing *multiple* Paragraph Style combinations at once
                    rndlm Level 1

                    Thanks for your interesting scripts, I'm going to study and save them for the future!