Copy link to clipboard
Copied
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.
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
}
}
app.findTextPreferences = app.changeTextPreferences = null
//}catch(e){}
}
Copy link to clipboard
Copied
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
Copy link to clipboard
Copied
Hi,
yes, same error is occuring for the reverse order loop.
Copy link to clipboard
Copied
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
Copy link to clipboard
Copied
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.
Copy link to clipboard
Copied
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
Copy link to clipboard
Copied
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?
Copy link to clipboard
Copied
Hi,
No changes except activation of reverse order.
Works with textFrame selected or some text selected.
Win, CS5
Jarek
Copy link to clipboard
Copied
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.