6 Replies Latest reply on Jan 18, 2009 2:01 PM by federico platon

    MapStylesToTags script

    federico platon Adobe Community Professional & MVP
      I would like to create automatically XML Tags using the naming of Paragraph (and Character if possible) styles used in an InDesign document.

      I have tried a CS2 script from The Real World InDesign CS3 book, but gives an error (in IDCS3 on a Mac the .as, and the .js, also in CS4 in Windows)

      I have found a demo example but it creates some tags in a new document named as detailed in the script)

      What I need to find is an script that takes the names of my text styles and makes tags with the same names.

      I have checked the Adobe Exchage site but have not found it either.

      Anyone can point me to somewhere. TIA
        • 1. Re: MapStylesToTags script
          Loic.Aigon Adobe Community Professional
          Hi <br />Sth like :<br /><br />var doc = app.activeDocument;<br />var myPgSt = doc.paragraphStyles.everyItem().getElements();<br /><br />for(i=2;i<myPgSt.length;i++)<br />{<br /><br />     doc.xmlTags.add(myPgSt[i].name);<br /><br />}<br /><br />I needed to start the loop to 2 to avoid the two basic styles as No paragraph & basic paragraphs<br />Loic
          • 2. Re: MapStylesToTags script
            Loic.Aigon Adobe Community Professional
            And in case you may want to relaunch the script...<br /><br />var doc = app.activeDocument;<br />var myPgSt = doc.paragraphStyles.everyItem().getElements();<br /><br />for(i=2;i<myPgSt.length;i++)<br />{<br /><br />     if(doc.xmlTags.item(String(myPgSt[i].name))==null)<br />     {<br />          doc.xmlTags.add(String(myPgSt[i].name));<br />     }<br /><br />}
            • 3. Re: MapStylesToTags script
              federico platon Adobe Community Professional & MVP
              Loic,

              Thank you, thank you very much. Yes it works perfectly, but it requires well formed names, style names cannot start with numbers, include some invalid characters or use spaces.

              I would like to be able to start with names of paragraph styles that include an space between two words, and replace it with a low dash.

              I think I should add a GREP search/replace, but the code strings I have found use a differnt syntax:

              var myRegEx = new RegExp (' ', 'gi') ;
              myStyleName = myStyleName.replace(myRegEx, '_');

              Could you please adapt it? Again, Thanks in advance
              • 4. Re: MapStylesToTags script
                Level 1
                myTagName = myStyleName.replace(" ", "_");
                • 5. Re: MapStylesToTags script
                  Loic.Aigon Adobe Community Professional
                  And what about changing paragraph styles 's names itselves ? Soon or later, won't you want to map tags to styles ? If they are named differently, you have to take it in account...
                  • 6. Re: MapStylesToTags script
                    federico platon Adobe Community Professional & MVP
                    Thanks Thomas I will check it later.

                    Loic thanks again, you are right. At the end when I prepare the layout for importing an XML data file I may need to map tags to styles and to assign them automatically, by using the same naming, paragraph style names should not include an space or other invalid characters.