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

[SCRIPTING] parentPage from found text

Enthusiast ,
Sep 17, 2020 Sep 17, 2020

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
2.3K
Translate
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

Translate
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

Translate
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

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

 

Translate
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

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. 

Translate
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

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
}
Translate
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

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

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

 

P.

Translate
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

No. It can return undefined.

 

1.JPG2.JPG3.JPG

Translate
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

True!

Translate
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
Mentor ,
Sep 20, 2020 Sep 20, 2020

An array has a length property …

Translate
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

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
Translate
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 ,
Aug 07, 2024 Aug 07, 2024

In regard to the Overset Text issue, is the following a good solve?

myobject.parentStory.textContainers[0].parentPage.documentOffset

Object hierarchy is always confusing for me, but this worked with an overset text script I had, and with your mention of it, I've plugged into another similar doc that searches strings and gives a page number.

Translate
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 ,
Aug 07, 2024 Aug 07, 2024

Yes, that looks like a safe approach.

Translate
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
LEGEND ,
Aug 07, 2024 Aug 07, 2024
LATEST

@wckdtall

 

I don't think it will work for Anchored TFs - that are in an overset text?

 

Translate
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

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 )

Translate
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