2 Replies Latest reply: Jul 31, 2012 8:17 AM by natewhoscripts RSS

    Indesign Crashes while Creating Tags

    natewhoscripts Community Member

      Hi There!

      I'm trying to find a way to take all of the styles from a document, turn them into tags, and map all of the styles to their corresponding tags automatically. This script works, but halfway through, it freezes and Indesign crashes without warning. This occurs in mac and windows, cs 5.5 and 6.

      The script is:

       

      var myDoc = app.activeDocument;
      var myPStyle = myDoc.allParagraphStyles;
      for (i=2; i<myPStyle.length; i++){
           var myPStyleName = myPStyle[i];
           try{
                var myXml = myDoc.xmlTags.add(String(myPStyle[i].name.replace(" ","-").split("/")[0].split(".")[0]));
                }catch(e){}
           app.findTextPreferences = app.changeTextPreferences = NothingEnum.nothing; 
           app.findTextPreferences.appliedParagraphStyle = myPStyleName;
           app.changeTextPreferences.markupTag=myPStyle[i].name.replace(" ","-").split("/")[0].split(".")[0];
           app.activeDocument.changeText(); 
           app.findTextPreferences = app.changeTextPreferences = NothingEnum.nothing; 
           }
      
      

       

      Any advice, or an alternative way of accomplishing this would be very welcome!

      Best,

      Nate

        • 1. Re: Indesign Crashes while Creating Tags
          csm_phil Community Member

          Hi Nate,

           

          I have mofied your above JS code, Please try this JS code.

           

           

          var myDoc = app.activeDocument;
          var myPStyle = myDoc.allParagraphStyles;
          for (i=2; i<myPStyle.length; i++){
               try{
                   var myPStyleName = myPStyle[i].name.replace(/[  ]+/g,'').split(".")[0].split("/")[0];
                   var myXml = myDoc.xmlTags.add(String(myPStyleName));
                   app.findGrepPreferences = app.changeGrepPreferences = NothingEnum.nothing; 
                   app.findGrepPreferences.findWhat= ".+(?=\\r)";
                   app.findGrepPreferences.appliedParagraphStyle = myPStyle[i].name;
                   app.changeGrepPreferences.markupTag=myXml;
                   myDoc.changeGrep(); 
                   app.findGrepPreferences = app.changeGrepPreferences = NothingEnum.nothing; 
                   }catch(e){}
               }
          

           

          thx

          csm_phil

          • 2. Re: Indesign Crashes while Creating Tags
            natewhoscripts Community Member

            That works brilliantly, thank you so much.