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

[SCRIPTING] parentPage from found text

Enthusiast ,
Sep 17, 2020 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) {}
}
TOPICS
Scripting

Views

1.1K

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
community guidelines

correct answers 1 Correct answer

Community Expert , Sep 17, 2020 Sep 17, 2020

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

Votes

Translate

Translate
Community Expert ,
Sep 17, 2020 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

Votes

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
community guidelines
Community Expert ,
Sep 17, 2020 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

 

Votes

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
community guidelines
Enthusiast ,
Sep 17, 2020 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. 

Votes

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
community guidelines
Participant ,
Sep 17, 2020 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
}

Votes

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
community guidelines
Community Expert ,
Sep 18, 2020 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.

Votes

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
community guidelines
Participant ,
Sep 18, 2020 Sep 18, 2020

Copy link to clipboard

Copied

No. It can return undefined.

 

1.JPG2.JPG3.JPG

Votes

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
community guidelines
Community Expert ,
Sep 18, 2020 Sep 18, 2020

Copy link to clipboard

Copied

True!

Votes

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
community guidelines
Guide ,
Sep 20, 2020 Sep 20, 2020

Copy link to clipboard

Copied

An array has a length property …

Votes

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
community guidelines
Community Expert ,
Sep 21, 2020 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

Votes

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
community guidelines
Community Expert ,
Sep 21, 2020 Sep 21, 2020

Copy link to clipboard

Copied

LATEST

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 )

Votes

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
community guidelines