Skip to main content
lfcorullon13651490
Legend
September 18, 2020
Answered

[SCRIPTING] parentPage from found text

  • September 18, 2020
  • 3 replies
  • 2392 views

Hello, there.

I'm performing a GREP find in a document and want to collect the contents and parentPage.name of each found text. But, some of them are in text frames placed in pasteboard. And, of course, the script is stopping with an error. Then I put it inside a try/catch and running from InDesign, it's OK. But running from ESTK the error is stopping the script. (Since when ESTK stops to respect try/catch?)

Is ther any other way to validate this other than try/catch?

 

app.findGrepPreferences = app.changeGrepPreferences = NothingEnum.NOTHING;
app.findGrepPreferences.findWhat = ".+";
app.findGrepPreferences.appliedParagraphStyle = ps;
var f = doc.findGrep();
app.findGrepPreferences = app.changeGrepPreferences = NothingEnum.NOTHING;
for (var k=0; k<f.length; k++) {
  try {
    collection.push([f[k].contents , f[k].parentTextFrames[0].parentPage.name]);
  } catch(e) {}
}
This topic has been closed for replies.
Correct answer Manan Joshi

There is an option to toggle this behavior in ESTK. See the screenshot

You need to have the option "Do Not Break On Guarded Expection" as on and it should be fine.

-Manan

3 replies

Community Expert
September 21, 2020

Hi lf_corullon,

note, that there are also "special" cases where parentPage returns a page object, but the object is not part of the page.

In this case the text frame cannot be found in page.allPageItems, but only in spread.allPageItems.

 

Here an example of such a special case:

 

var foundPage = app.selection[0].parentPage ; // returns: [object Page]
foundPage.pageItems.length // returns: 0

 

Regards,
Uwe Laubender

( ACP )

Community Expert
September 18, 2020

Also, did you check, the following should be null for textframe present on the pasteboard

f[k].parentTextFrames[0].parentPage

This could help you avoid try/catch. Give it a try

-Manan

 

-Manan
lfcorullon13651490
Legend
September 18, 2020

I tried to put exactly this line inside an if checking if it different (!=) of null to them push it to my collection array. But even this if statement stops the script. Maybe because that ESTK option I never ever know about. 

 

Thank you so much, Manan.

I'll try (and maybe catch, =D) tomorrow. 

SychevKA
Inspiring
September 18, 2020

hi, i was getting this error, my solution looks like this:

try{var test = myobject.parentTextFrames[0]}
catch(e){}
if(typeof test == 'undefined'){
	// your code here
}
Manan JoshiCommunity ExpertCorrect answer
Community Expert
September 18, 2020

There is an option to toggle this behavior in ESTK. See the screenshot

You need to have the option "Do Not Break On Guarded Expection" as on and it should be fine.

-Manan

-Manan