Article View: adobe.scripting.indesign
Article #338[CS3 JS] event crashes InDesign
From: Rasmus_Olsen
Date: Thu, 26 Mar 2009 15:19
Date: Thu, 26 Mar 2009 15:19
61 lines
2929 bytes
2929 bytes
Scripting ladies and gentlemen,
I'm working on this event script that searches for linked PDF files and lets the user copy/relink them. Using the afterOpen eventListener however crashes InDesign no matter what I do. This is also the case with beforeClose. It appears that my function cnvrtPDFlnk is causing the crash (I'm able to alert succesfully with the afterOpen event if I //-comment the cnvrtPDFLnk(myDocument)). Do one of you scripting gurues have a hint?
#targetengine "session"
main();
function main() {
app.addEventListener("afterOpen", myEventFunction, false);
}
function myEventFunction(myEvent) {
var myDocument = myEvent.parent;
var label = docLabel(myDocument, "PDFCheck");
if(label) {
//myEvent.stopPropagation();
//myEvent.preventDefault();
exit();
}
else {
cnvrtPDFLnk(myDocument);
}
}
function docLabel(myDocument, key) {
var hasLabel = (eval(myDocument.extractLabel(key))?true:false);
return hasLabel;
}
function cnvrtPDFLnk(myDocument) {
var graphics = myDocument.allGraphics;
var link; var linkExt; var linkType; var linkPath; var linkPageRef; var myConfirm; var myFolder; var myFile; var myOrgPath;
var myLinkObjects = [];
for (var i = 0; i < graphics.length; i++) {
link = graphics[i].itemLink;
linkExt = link.filePath.split('.').pop().toLowerCase();
linkType = link.linkType.toLowerCase();
if (linkExt == 'pdf' || linkType.match('pdf') != null) {
link.show();
if(myConfirm= confirm(link.name+"\nDo you want to convert this link?")?myLinkObjects.push(link):alert("Link skipped!\n"+link.name));
}
}
if (myLinkObjects.length > 0) {
myFolder = Folder.selectDialog("Point me to a hotfolder..");
copyLink(myLinkObjects, myFolder); // run copyLink function - copies links according to myfolder
if(myConfirm = confirm("Do you want to relink now?")) {
reLink(myLinkObjects); // run reLink function - relinks according to myFile dialogue
app.menuActions.item("Fit Page in Window").invoke();
app.menuActions.item("First Page").invoke();
}
myDocument.insertLabel("PDFCheck", "true");
}// no links
}// end cnvrtPDFLnk
Best regards,
Rasmus
Technical Details
Message-ID:
<59b86a93.-1@webcrossing.la2eafNXanI>Path:
arc1-ca.pugleaf.net!g2news2.google.com!news1.google.com!news.glorb.com!news2.glorb.com!newshub.sdsu.edu!webcrossingShow Full Headers
Complete Article Headers
X-Google-Thread: f939a,d51bfd07ae7dff66,start X-Google-Attributes: gidf939a,domainid0,public,usenet X-Google-Language: ENGLISH,ASCII-7-bit From: Rasmus_Olsen@adobeforums.com Path: arc1-ca.pugleaf.net!g2news2.google.com!news1.google.com!news.glorb.com!news2.glorb.com!newshub.sdsu.edu!webcrossing Newsgroups: adobe.scripting.indesign Subject: [CS3 JS] event crashes InDesign Message-ID: <59b86a93.-1@webcrossing.la2eafNXanI> Date: Thu, 26 Mar 2009 08:19:55 -0700 Lines: 77 MIME-Version: 1.0 Content-Type: text/plain; charset="ISO-8859-1" Content-Transfer-Encoding: 8bit