11 Replies Latest reply on Aug 1, 2013 6:36 AM by HectorBragado

    [JS IDCS5] Create tags from paragraph styles

    stoereee Level 1

      Hello,

       

      I would like to iterating through al the paragraph styles within a document to create there tags from. The tags should have the same name as the paragraph styles. Is that possible and how?

       

      Regards, Sjoerd

        • 1. Re: [JS IDCS5] Create tags from paragraph styles
          csm_phil Level 4

          Hi Sjord,

           

          What i am understand, i think you mean xml tag apply the appropriate paragraph style,  this way you can use th MAP Tag to Style in InDesign.

          Can you please give sample or clearly tell your work flow

           

          thx

          csm_phil

          • 2. Re: [JS IDCS5] Create tags from paragraph styles
            stoereee Level 1

            Hi Phil,

             

            First of all, there is no XML. I would like to make XML from a InDesign document. So the script is creating tags from the existing paragraph styles and then it will be mapped by name after (also with scripting).

            • 4. Re: [JS IDCS5] Create tags from paragraph styles
              csm_phil Level 4

              Hi Serjod,

               

               

              You can try the below JS code i hope you expect this!

               

               

              var myDoc = app.activeDocument;
              var myPStyle = myDoc.paragraphStyles;
              //var myAllPStyle = myDoc.allParagraphStyles; if you want this enable a line all the folder paragraph styles also consider
              for (i=2; i<myPStyle.length; i++){
                   var myPStyleName = myPStyle[i];
                   //alert(myPStyleName.name);
                   try{
                        var myXml = myDoc.xmlTags.add(String(myPStyleName.name));
                        }catch(e){}
                   app.findTextPreferences = app.changeTextPreferences = NothingEnum.nothing; 
                   app.findTextPreferences.appliedParagraphStyle = myPStyleName;
                   app.changeTextPreferences.markupTag=myPStyle[i].name;
                   app.activeDocument.changeText(); 
                   app.findTextPreferences = app.changeTextPreferences = NothingEnum.nothing; 
                   }
              
              

               

              thx

              csm_phil

              • 5. Re: [JS IDCS5] Create tags from paragraph styles
                stoereee Level 1

                Perfect! This is it! Thank you Phil

                • 6. Re: [JS IDCS5] Create tags from paragraph styles
                  Mac_06 Level 2

                  You could use Indesign map style to tag functioality

                   

                  var Doc = app.activeDocument;
                  var currentParaStyle = Doc.paragraphStyles.item("Test")
                  var currentTag = Doc.xmlTags.add(currentParaStyle.name);
                  Doc.xmlExportMaps.add(Doc.paragraphStyles.item(currentParaStyle.name), Doc.xmlTags.item(currentTag.name));
                  Doc.mapStylesToXMLTags();
                  
                  • 7. Re: [JS IDCS5] Create tags from paragraph styles
                    Mac_06 Level 2

                    Sorry... for back to back answer din't check at all

                    • 8. Re: [JS IDCS5] Create tags from paragraph styles
                      Andres_Mendoza

                      Hello,

                       

                      The example above,  trully maps a Paragraph Style Name to a tag.

                      But what about if we would like to export that Paragraph Style Name to a Tag.Class combination on a CSS stylesheet?,

                      just like on the Paragraph_Styles>Menu>Edit_All_Export_Tags palette on InDesign CS5.5

                       

                      Example:

                      say we have a Paragraph Style Name = h2.indented

                       

                      If we would use the example above, the style definition on the Template.css created when exporting as an ePub would be:

                      p.h2-indented {...}

                       

                      (it defines every style under paragraph style and changes every dot on the name for a hyphen)

                      And what we would really expect is:

                      h2.indented {...}

                       

                      I have been trying to use:

                      styleExportTagMaps.add(exportTypeParam, exportTagParam, exportClassParam, exportAttributesParam, withPropertiesParam);


                      , but don't know what what values should you send for parameters 1, 4 and 5.

                       

                      Thanks in advance,

                      Andres

                      • 9. Re: [JS IDCS5] Create tags from paragraph styles
                        Andres_Mendoza Level 1

                        Hello, I've found the answer to this one,

                         

                        A possible parameter for exportTypeParam (param 1) is "EPUB"; maybe you could try with "PDF"

                        The Attributes String (param 4) is composed by any combination of the ParagraphStyle properties.

                         

                        I hope this would be usefull to anybody.

                         

                        Ciao

                        Andres.

                        • 10. Re: [JS IDCS5] Create tags from paragraph styles
                          HectorBragado

                          Hi Phil,

                           

                          Absolute beginer here. The script creates tags for the styles outside groups, but for some reason it doesn't create the tags out of the Paragraph Styles in folders.

                          I enabled the line below and tried to change the "myPStyle"  for "myAllPStyle" in the following lines, but still nothing. Gives error when reaches the line myDoc.changeText();

                          Any hint?

                           

                          var myAllPStyle = myDoc.allParagraphStyles; //if you want this enable a line all the folder paragraph styles also consider

                           

                          for (i=2; i<myAllPStyle.length; i++){

                               var myAllPStyleName = myAllPStyle[i];

                               //alert(myPStyleName.name);

                               try{

                                    var myXml = myDoc.xmlTags.add(String(myAllPStyleName.name));

                                    }catch(e){}

                               app.findTextPreferences = app.changeTextPreferences = NothingEnum.nothing;

                               app.findTextPreferences.appliedParagraphStyle = myAllPStyleName;

                               app.changeTextPreferences.markupTag=myAllPStyle[i].name;

                               myDoc.changeText();

                               app.findTextPreferences = app.changeTextPreferences = NothingEnum.nothing;

                               }

                           

                          Also, how can I make it Map the tags with the PStyles by name after with the script?

                           

                          Thanks so much

                           

                          Hector

                          • 11. Re: [JS IDCS5] Create tags from paragraph styles
                            HectorBragado Level 1

                            I realized that the problem were the names of my Paragraph Styles, they begin with 01, 02... With no numbers at the begining of the name and no underscores, everything works perfect.

                            Still not able to map them by name automatically. Any solution for this?

                             

                            Thanks again

                             

                            hector