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[r].changeText();
}
}
app.findTextPreferences = app.changeTextPreferences = null
//}catch(e){}
}