Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

Issue in paragraph iterate

Contributor ,
Feb 21, 2014 Feb 21, 2014

Hi,

  When Im finding the paragraph texts using findTextPreference, its returning more than one paragraph.  I am replacing inline icons and getting contents for each paragraph. This process is working for only first para. For 2nd para, its throwing object invalid.  I need to do this process for all paragraphs found in the search.

Screen shot 2014-02-21 at 1.19.54 PM.png

Code :

        app.findTextPreferences = app.changeTextPreferences = null;

        app.findTextPreferences.appliedParagraphStyle = "styl1";

        var boldKey = app.selection[0].findText();

        var keyArrStr = "";

        alert("boldKey" +boldKey.length)

        for(var cnt = 0 ; cnt < boldKey.length; cnt ++)

        //for(var cnt =  boldKey.length-1; cnt >= 0 ;cnt --)

        {           

             //app.activeDocument.recompose()

            boldKey[cnt].select()

            alert("Sel Conts : BEFORE .." +boldKey[cnt].contents+"\tPara count " + boldKey[cnt].paragraphs.length)

            for(var pCnt = 0; pCnt <  boldKey[cnt].paragraphs.length; pCnt++)

            //for(var pCnt = boldKey[cnt].paragraphs.length -1 ; pCnt >= 0; pCnt--)

            {

                app.selection=1851876449;

               

                var curPara = boldKey[cnt].paragraphs[pCnt];

                findAndReplace(curPara, "^a","");              

                alert("Process " + pCnt+ "*"+curPara.contents+"*"+"\nCount "+curPara.contents.length)

            }

        }

        app.findTextPreferences = app.changeTextPreferences = null;

     function findAndReplace(docTF,fndCont,chgCont)

     {

          //try{

           app.findTextPreferences = app.changeTextPreferences = null;       

           app.findTextPreferences.findWhat=fndCont;

           app.changeTextPreferences.changeTo=chgCont;

           var sRes=docTF.findText();

           if(sRes.length > 0){

              for(var r=sRes.length-1;r>=0;r--){                       

                    sRes.changeText();       

              }

           }

            app.findTextPreferences = app.changeTextPreferences = null

        //}catch(e){}

     }

TOPICS
Scripting
1.2K
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Mentor ,
Feb 21, 2014 Feb 21, 2014

Hi,

Both 1st and 2nd .findText() method return arrays of "index_related" objects.

So while you modify them - you change this relation as well.

Make a loop in reverse order (what is commented currently). Did you try and fail?

Jarek

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Contributor ,
Feb 21, 2014 Feb 21, 2014

Hi,

   yes, same error is occuring for the reverse order loop.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Mentor ,
Feb 21, 2014 Feb 21, 2014

Hm...

It means some textRanges from 1st found array are empty (.paragraphs[0].isValid returns "false").

I.e. empty textFrame has applied default paraStyle (so .findText() counts it) but has not paragraphs.

I suggest to include if (curPara.isValid) {....} to exclude those cases.

Jarek

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Contributor ,
Feb 21, 2014 Feb 21, 2014

Its having only 3 paragraphs. All three paras contains text.  Its return all paragraphs text (3 paras) when I iterate the loop to get contents alone.  But when I use the method to replace "Inline Icon" (findAndReplace(curPara, "^a","") ), then only its throwing error.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Mentor ,
Feb 21, 2014 Feb 21, 2014

Hi,

I run your code with simple example (reverse order) - one textFrame selected with some text with some inline graphics. It passed without errors.

What is your selection?

Jarek

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Contributor ,
Feb 21, 2014 Feb 21, 2014

My selection is paragraphs with the same style.  Here all paragraphs in a textFrame.

For me, its not working dono why. Did u changed anything in code?

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Mentor ,
Feb 22, 2014 Feb 22, 2014

Hi,

No changes except activation of reverse order.

Works with textFrame selected or some text selected.

Win, CS5

Jarek

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Contributor ,
Feb 23, 2014 Feb 23, 2014
LATEST

Hi,

Sorry....

I had tested in InDesign CS4, 5.5 and 6.  But throwing  the same error.  Dono where i did mistake or any issue in my sample.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines