Skip navigation
natewhoscripts
Currently Being Moderated

Indesign Crashes while Creating Tags

Jul 30, 2012 1:16 PM

Tags: #tags #text #javascript #indesign #xml #scripting

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

 
Replies
  • Currently Being Moderated
    Jul 30, 2012 11:05 PM   in reply to natewhoscripts

    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

     
    |
    Mark as:

More Like This

  • Retrieving data ...

Bookmarked By (0)

Answers + Points = Status

  • 10 points awarded for Correct Answers
  • 5 points awarded for Helpful Answers
  • 10,000+ points
  • 1,001-10,000 points
  • 501-1,000 points
  • 5-500 points