Js error 45 "Object is Invalid"
Hi Community.
I'm trying to write a small script that would fix the inconsistent numbered list paragraphs when the date of creation of text frames does not he follow the layout.

So here's the script:
var myDocument = app.documents.item(0);
var myParaStyle = "numbered";
var myFrames = [];
//create collection
for (i = 0; i < myDocument.textFrames.length; i++) {
if (myDocument.textFrames.paragraphs[0].appliedParagraphStyle.name == myParaStyle) {
myFrames.push(myDocument.textFrames);
}
}
//sort collection
function sortFramesinArray(a, b) {
if (Math.round(a.geometricBounds[1]) === Math.round(b.geometricBounds[1])) {
return Math.round(a.geometricBounds[0]) - Math.round(b.geometricBounds[0]);
}
return Math.round(a.geometricBounds[1]) - Math.round(b.geometricBounds[1]);
}
myFrames.sort(sortFramesinArray);
// cut and paste in place
for (i = 0; i < myFrames.length; i++) {
myFrames.select();
app.cut();
app.pasteInPlace();
}
I've tested it on a very basic CS6 document and it seems to be working.
Now, tested by another user on a CS5.5 document, the script returns a 45 "Object is Invalid" error.
See here: automatic numbering gone wrong
Could anyone advice on why this happened? Is a script issue (I'm a beginner), a document issue, or a Indd version issue?
Thanks in advance for your enlightening help.
Vinny


