10 Replies Latest reply on Aug 29, 2012 1:17 AM by R-Bala-Krishnan

    Replace language of styles in Style Group

    Kel Dugal

      Hi All,

       

      Can someone help modify my script so it could also edit styles in Style Group. I tried several time  by creating a nested loop under another the variable for paragraphStyleGroups but I can't get it to work.

       

       

      myDoc = app.activeDocument;

      myStyles = myDoc.paragraphStyles;

      myCStyles = myDoc.characterStyles;

      for (i = 1; i < myStyles.length; i++)

      {

      myStyle = myStyles[i];

      myStyle.appliedLanguage = "Spanish";

      }

       

      for (i = 1; i < myCStyles.length; i++)

      {

      myCStyle = myCStyles[i];

      myCStyle.appliedLanguage = "Spanish";

      }

       

       

      Your help will be appreciated.

       

      Thanks,

       

      Kel

        • 1. Re: Replace language of styles in Style Group
          Harbs. Level 6

          Just change myDoc.paragraphStyles to myDoc.allParagraphStyles

           

          and myDoc.characterStyles to myDoc.allCharacterStyles

           

          Harbs

          1 person found this helpful
          • 2. Re: Replace language of styles in Style Group
            Shonkyin Level 3

            Use allParagraphStyles and allCharacterStyles.

             

            myStyles = myDoc.allParagraphStyles;

            myCStyles = myDoc.allCharacterStyles;

             

             

            Shonky

            • 3. Re: Replace language of styles in Style Group
              Shonkyin Level 3

              oops, i had opened thread and reply late.

              • 4. Re: Replace language of styles in Style Group
                Kel Dugal Level 1

                It work. Thank you so much.

                • 5. Re: Replace language of styles in Style Group
                  SaaiMurugan_81

                  Hi Harbs

                   

                  I need to change the Name of the Styles using a Script.

                   

                  If the Style is not in a Group the below script works but if the style is in a Group it is not getting renamed.

                      

                         var myDoc=app.activeDocument;

                         var myStyle=myDoc.paragraphStyles.itemByName(oldStyle);
                         alert(oldStyle);
                         alert(newStyle);
                         myStyle.name=newStyle;

                   

                  Please HELP!!!

                   

                  Thanks

                  Saai

                  • 6. Re: Replace language of styles in Style Group
                    SaaiMurugan_81 Level 1

                    Hi Shonky

                     

                    I need to change the Name of the Styles using a Script.

                     

                    If the Style is not in a Group the below script works but if the style is in a Group it is not getting renamed.

                       

                           var myDoc=app.activeDocument;

                           var myStyle=myDoc.paragraphStyles.itemByName(oldStyle);
                           alert(oldStyle);
                           alert(newStyle);
                           myStyle.name=newStyle;

                     

                    Please HELP!!!

                     

                    Thanks

                    Saai

                    • 7. Re: Replace language of styles in Style Group
                      Shonkyin Level 3

                      If you want change style name  within group then you need to go through all style compare with your old  style and rename with new one.

                       

                      Check below code:

                       

                      var myDoc=app.activeDocument;
                      var myallParaSyles = myDoc.allParagraphStyles;
                      for(a=2; a<myallParaSyles.length; a++)
                      {
                           if (myallParaSyles[a].name == oldStyle);
                           {
                                myallParaSyles[a].name  = newStyle;
                           }
                      }

                       

                       

                      Shonky

                      • 8. Re: Replace language of styles in Style Group
                        R-Bala-Krishnan Level 2

                        Hi Saai,

                         

                        Footnote creation:

                         

                        var doc,  root,  childs,  max = 0; 

                        if(app.documents.length==0)

                        {}else

                            doc = app.activeDocument; 

                            root = doc.xmlElements[0]; 

                            childs = root.evaluateXPathExpression("//footnote"); 

                            max = childs.length; 

                            if(max==0){}else{ 

                                alert(max);

                                for(var i = 0; i< max; i++){ 

                                    childs[i].xmlContent.select();

                                    var fnText = app.activeDocument.selection[0]; 

                                    var fNote = app.activeDocument.selection[0].footnotes.add(LocationOptions.BEFORE, fnText.insertionPoints[0]); 

                                    fNote.texts[0].insertionPoints[-1].contents = fnText.contents;

                                    fnText.remove();

                                    } 

                                }

                            }

                        • 9. Re: Replace language of styles in Style Group
                          SaaiMurugan_81 Level 1

                          Dear Bala

                           

                          Please help me with the below.

                           

                            <section id="ch12lev1bm" role="bm">

                             <title id="ch12lev1bm.title"/>

                             <para aid:pstyle="CHAP_BM_FIRST">The foreign-exchange market is the market where domestic money can be exchanged for foreign, and hence it is where the prices of many currencies are set. The price of foreign money is known as the <link linkend="ch12mn01" preference="1" type="forward">

                               <keyterm id="ch12term01" role="strong" linkend="ch12gloss01_01" preference="0" aid:cstyle="KT">exchange rate</keyterm>

                               <?boxCitation type=MN3?>

                              </link>

                              <emphasis role="strong" aid:cstyle="BOLD">,</emphasis> denoted throughout the text by the letter E. Unlike the New York Stock Exchange, the foreign-exchange market is not located in any one location. Rather, it is best thought of as a worldwide network of commercial banks linked together by a sophisticated communications technology. Without doubt, it is the world’s largest market; current estimates place the volume of average <emphasis aid:cstyle="ITAL">daily</emphasis> worldwide trade at $4 trillion.<footnoteref preference="1" label="1" linkend="ch12fn01">

                               <insert aid:cstyle="SUP">1</insert>

                              </footnoteref> It is also one of the most efficient. It is characterized by low barriers to entry, a homogeneous commodity (money), many buyers and sellers none of whom has significant market power, and almost perfect information. Thus, it possesses all of the characteristics of a perfectly competitive market. And, because of its overall size and international dimensions, it is totally unregulated by any national or international government.</para>

                             <footnote id="ch12fn01" label="1">

                              <insert aid:cstyle="SUP">1</insert>

                              <para aid:pstyle="FN">

                               <emphasis aid:cstyle="ITAL">Triennial Central Bank Survey: Report on global foreign exchange market activity in 2010</emphasis> (Basel: Bank for International Settlements, December 2010). Available at: <ulink url="http://www.bis.org/publ/rpfxf10t.pdfhttp://www.bis.org/publ/rpfxf10t.pdf">http://www.bis.o rg/publ/rpfxf10t.pdf</ulink>. See the summary of main findings for more detail.</para>

                             </footnote>

                             <marginalnote id="ch12mn01" float="1" type="mn3">

                              <glossary id="ch12gloss01">

                               <glossentry id="ch12gloss01_01">

                                <glossterm aid:pstyle="MN3_GLOS_GT">Exchange rate</glossterm>

                                <insert>&#13;</insert>

                                <glossdef>

                                 <para aid:pstyle="MN3_GLOS_DEF">The price of one country’s money in terms of another.</para>

                                </glossdef>

                               </glossentry>

                              </glossary>

                             </marginalnote>

                             </section>

                           

                          Use this for testing,

                          1. the <insert aid:cstyle="SUP">1</insert> should be be moved

                           

                          Thanks

                          Saai Murugan

                          • 10. Re: Replace language of styles in Style Group
                            R-Bala-Krishnan Level 2

                            var doc,  root,  childs,  max = 0; 

                            if(app.documents.length==0)

                            {}else

                                doc = app.activeDocument; 

                                root = doc.xmlElements[0]; 

                                childs = root.evaluateXPathExpression("//footnote"); 

                                max = childs.length; 

                                if(max==0){}else{ 

                                    alert(max);

                                    for(var i = 0; i< max; i++){             

                                         for(var i1=0; i1 < childs[i].xmlElements.length; i1++) {

                                             switch (childs[i].xmlElements[i1].markupTag.name){

                                                 case "insert":

                                                 var myLabel = childs[i].xmlElements[i1];                    

                                                 break;

                                                 case "para":

                                                 var myText = childs[i].xmlElements[i1];                    

                                                 break;

                                                 default:

                                                 break;

                                                 }

                                             }

                                        childs[i].xmlContent.select();

                                        var fnText = app.activeDocument.selection[0]; 

                                        var fNote = app.activeDocument.selection[0].footnotes.add(LocationOptions.BEFORE, fnText.insertionPoints[0]); 

                                        app.select(myText.xmlContent);

                                        app.copy();

                                        app.select(fNote.texts[0].insertionPoints[-1]);

                                        app.paste();

                                        //myText.remove();/*If need to remove tag also*/

                                        //myLabel.remove();/*If need to remove tag also*/

                                        myText.xmlContent.remove();

                                        myLabel.xmlContent.remove();

                                        } 

                                    }

                                }