Highlighted

[SCRIPTING] parentPage from found text

Enthusiast ,
Sep 17, 2020

Copy link to clipboard

Copied

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) {}
}
Adobe Community Professional
Correct answer by Manan Joshi | Adobe Community Professional

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

Screenshot 2020-09-18 at 9.58.22 AM.png

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

-Manan

TOPICS
Scripting

Views

169

Likes

Translate

Translate

Report

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

[SCRIPTING] parentPage from found text

Enthusiast ,
Sep 17, 2020

Copy link to clipboard

Copied

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) {}
}
Adobe Community Professional
Correct answer by Manan Joshi | Adobe Community Professional

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

Screenshot 2020-09-18 at 9.58.22 AM.png

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

-Manan

TOPICS
Scripting

Views

170

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Sep 17, 2020 0
Adobe Community Professional ,
Sep 17, 2020

Copy link to clipboard

Copied

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

Screenshot 2020-09-18 at 9.58.22 AM.png

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

-Manan

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Sep 17, 2020 1
Adobe Community Professional ,
Sep 17, 2020

Copy link to clipboard

Copied

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

 

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Sep 17, 2020 0
Enthusiast ,
Sep 17, 2020

Copy link to clipboard

Copied

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. 

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Sep 17, 2020 0
Participant ,
Sep 17, 2020

Copy link to clipboard

Copied

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
}

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Sep 17, 2020 0
Adobe Community Professional ,
Sep 18, 2020

Copy link to clipboard

Copied

If  myobject.parentTextFrames[0] return null, the frame is overset.

If  myobject.parentTextFrames[0].parentPage returns null, the frame is on the pasteboard.

 

P.

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Sep 18, 2020 0
Participant ,
Sep 18, 2020

Copy link to clipboard

Copied

No. It can return undefined.

 

1.JPG2.JPG3.JPG

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Sep 18, 2020 0
Adobe Community Professional ,
Sep 18, 2020

Copy link to clipboard

Copied

True!

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Sep 18, 2020 0
Advisor ,
Sep 20, 2020

Copy link to clipboard

Copied

An array has a length property …

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Sep 20, 2020 1
Adobe Community Professional ,
Sep 21, 2020

Copy link to clipboard

Copied

So, as so often, there's more than one way to skin a cat. All these return true:

myobject.parentTextFrames[0] == undefined
myobject.parentTextFrames[0] == null
myobject.parentTextFrames.length == 0

myobject.parentTextFrames[0].parentPage == null
myobject.parentTextFrames[0].parentPage == undefined

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Sep 21, 2020 1
Adobe Community Professional ,
Sep 21, 2020

Copy link to clipboard

Copied

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:

parentPage-returnsPageObject.PNG

 

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

 

Regards,
Uwe Laubender

( ACP )

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Sep 21, 2020 1