7 Replies Latest reply on Jun 28, 2013 3:13 AM by aanavaras

    finding text[o].properties & apply created p.styles.

    Wander5 Level 1

      Hi Forum,

       

      I have created the paragraphStyles by finding every.paragraph.text[o].insertionPoints[0].properties.

       

      Now again, i'm finding every.paragraph.text[0].insertionPoints[0].properties and replacing with the created paragraph styles, which matches the same properties.

       

      I have tried in way, applying the paragraphStyle created to paras that has same text[0].insertionPoint[0].properties. But all the bullets and numbering seems to be disappeared.

       

      when i edit and appy bullets in paragraphStyle, i can reback the lost bullet and numbering to the paras lost.

       

      Can i get help to apply the paragraph style created to the matching to the same paras.text[0].insertionPoints.properties.

       

      this is my bad script...and also it consumes lot of time to create paragraphstyles.

       

      var myParagraphs = app.activeDocument.stories.everyItem().paragraphs.everyItem().getElements();

      for (var n = 0; n < myParagraphs.length; n++){

                 if(myParagraphs[n].appliedParagraphStyle.name != '') {

       

                     var par = myParagraphs[n].texts[0].insertionPoints[0];

      app.findTextPreferences  = app.changeTextPreferences = NothingEnum.NOTHING;

      app.findTextPreferences.properties = par.properties;

      app.activeDocument.paragraphStyles.add();

      app.changeTextPreferences.appliedParagraphStyle = app.activeDocument.paragraphStyles.lastItem(par-1);

      app.changeTextPreferences.appliedCharacterStyle = null;

      app.changeText();

      continue

      }}

       

      Please help on this paras.

        • 1. Re: finding text[o].properties & apply created p.styles.
          aanavaras Level 1

          Hello,

           

          i just tested your script and my comments are below:

           

          Your script is not finding. it returns '0' on alert(app.findText().length);

          I'm sure that app.findTextPreferences.properties = par.properties; causes this.

           

          and I think 'all the properies were not set to the created paragraphStyle' so that the style was not applied properly...

           

          Rather than setting all props to the prefs, you can try by setting major props.

           

          Let me know if i'm wrong.!

          • 2. Re: finding text[o].properties & apply created p.styles.
            Wander5 Level 1

            Hi aanavaras,

             

            thanks for the speedy reply,

             

            As i m new to scripting area and not well profound in this, i cant able to conclude and make idea for the last point said.

             

            If you could able to do a tweak and post that would be great.

             

            thanks

            • 3. Re: finding text[o].properties & apply created p.styles.
              Wander5 Level 1

              Hi aanavaras,

               

              I also tried using

              for (i =0; i<result.length; i++) {

                  re = result [i];

               

              it, applied only to the first find and quit.

               

              Any help...

              • 4. Re: finding text[o].properties & apply created p.styles.
                Wander5 Level 1

                Hi Forum,

                 

                After the long try and with big bang headache, i could find atleast this.

                Now i can able to find and replace the paragraphs with the same properties.

                 

                But the problem is, creating more than 50 paragraphStyles and when deleted unused styles, the really applied is only 5 to 6 styles.

                 

                Next, the script run very slow (even the doc is only 10 pages).

                 

                Im requesting to tweak my script to create only the wanted paragraphs and to impove the speedness of the script. please help...

                 

                var myParagraphs = app.activeDocument.stories.everyItem().paragraphs.everyItem().getElements();

                for (var n = 0; n < myParagraphs.length; n++){

                 

                var par = myParagraphs[n].texts[0].insertionPoints[0];

                 

                app.findTextPreferences.properties = par.properties;

                //var df = app.findText();

                 

                    app.findTextPreferences.properties = par.properties;

                    var tt =app.activeDocument.paragraphStyles.add();

                    with (tt) {

                    tt.pointSize = par.pointSize,

                    tt.leftIndent = par.leftIndent,

                    tt.bulletsCharacterStyle = par.bulletsCharacterStyle,

                    tt.bulletsAndNumberingListType = par.bulletsAndNumberingListType;

                    tt.bulletsAndNumberingListType.NumberingRestartPolicy= par.bulletsAndNumberingListType.NumberingRestartPolicy;

                    tt.tabList = par.tabList;

                tt.nextStyle = app.documents[0].paragraphStyles.item("[No Paragraph Style]") ;

                        app.changeTextPreferences.appliedParagraphStyle =tt;

                        app.changeText();

                   

                }

                 

                Please help me to solve this...

                • 5. Re: finding text[o].properties & apply created p.styles.
                  aanavaras Level 1

                  The reason for so many paragraphStyles is, you are creating paragraphStyles for each para's.

                  add a condition which checks for the paragraphStyle with the same property of selected para and apply that paragraph style for the para.

                   

                  Also, check whether the applied paragraph style of selected para is same as the one you are going to replace (which was already applied on your earlier replace). bcz, you are already replaced the paragraphs of the same properties.

                   

                  This will reduce the time of applying paragraphStyle for the paras which you aleady applied.

                   

                  –SaRaVaNaN.N

                  • 6. Re: finding text[o].properties & apply created p.styles.
                    Wander5 Level 1

                    Hi Forum,

                     

                    previously i was using the script like this...

                     

                    var newpara = app.activeDocument.paragraphStyles.add();

                    newpara.properties = app.documents[0].selection[0].insertionPoints[0].properties;

                     

                    and

                     

                    app.changeTextPreferences.appliedParagraphStyle = app.activeDocument.paragraphStyles.lastItem();

                    app.changeText();

                     

                    this is what, I place the cursor at the beginning of the paragraph and create styles..

                     

                    but, for the above post, I'm trying to place the cursor automatically at the paragraphs beignning and create styles, on its own..

                     

                     

                    I'm wondering, how can i do it or Can i be able to complete the task.

                     

                    Any help on this forum. I'm struggling to find the way..

                    • 7. Re: finding text[o].properties & apply created p.styles.
                      aanavaras Level 1

                      Hi Wander5,

                       

                      Did you modified the script as i suggested?

                       

                      The reason for so many paragraphStyles is, you are creating paragraphStyles for each para's.


                      add a condition which checks for the paragraphStyle with the same property of selected para and apply that paragraph style for the para.

                       

                      Also, check whether the applied paragraph style of selected para is same as the one you are going to replace (which was already applied on your earlier replace). bcz, you are already replaced the paragraphs of the same properties.

                       

                      This will reduce the time of applying paragraphStyle for the paras which you aleady applied.

                       

                      the above said modification will solve your problem...