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) {}
}
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
Copy link to clipboard
Copied
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
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
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.
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
}
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.
Copy link to clipboard
Copied
No. It can return undefined.
Copy link to clipboard
Copied
True!
Copy link to clipboard
Copied
An array has a length property …
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
Copy link to clipboard
Copied
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.
Copy link to clipboard
Copied
Yes, that looks like a safe approach.
Copy link to clipboard
Copied
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:
var foundPage = app.selection[0].parentPage ; // returns: [object Page]
foundPage.pageItems.length // returns: 0
Regards,
Uwe Laubender
( ACP )