7 Replies Latest reply on Mar 29, 2009 11:35 PM by (Rasmus_Olsen)

    [CS3 JS] event crashes InDesign

    Level 1
      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 tip?

      #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
        • 1. Re: [CS3 JS] event crashes InDesign
          Kasyan Servetsky Level 5
          Hi Rasmus,

          This problem was discussed earlier:
          http://www.adobeforums.com/webx/.59b71ef3/1
          http://www.adobeforums.com/webx?128@@.59b6ab75

          Instead of InDesign’s afterOpen event use Rorohico APID Toolkit’s docLoaded event. It works ok.

          Kasyan
          • 2. Re: [CS3 JS] event crashes InDesign
            Level 1
            Cheers Kasyan,

            My apologies for bugging you with answers allready answered. Those were very informative links.
            May I have a peek at the part of the script where you use the docLoadedEvent
            (you mention this script in "AddEventListener afterOpen to Document" thread by mattp)?

            Regards,
            Rasmus
            • 3. Re: [CS3 JS] event crashes InDesign
              Kasyan Servetsky Level 5
              Hi Rasmus,

              Here is an example of scripted plug-in — very simple yet useful for me.
              Its goal is to check color settings in InDesign and Photoshop after a document opens. We use two profiles at work: one for the main part of our magazine and another profile for its cover and the inset for another magazine. Sometimes, although rarely, we forget to switch on the correct setting.
              That's where the plug-in comes to the aid. After a document opens it checks if the file name contains certain characters – e.g. if file name starts with "Obl_" that means that this is a cover and the script checks the color settings, if they are not correct it gives warning.

              Here is short description of how to do it:
              Create a new scripted plug-in project from APIDTemplate.indd file.
              Open APID panel
              Enter 'docLoaded' into Event Filter field and press Enter
              Here is the script that does the job (the script file is generated in the same folder as indd-file):


              if (theItem.eventCode == "docLoaded") {
                 var gKasmyDoc = app.activeDocument;
                 var gKasDocumentName = app.activeDocument.name;
                 KasCheckProfile();
                 KasinfoFromPS();
              }

              function KasCheckProfile(){

                 var myIssueNumber = parseInt(gKasDocumentName.substr(2, 3));
                 if (gKasDocumentName.substr(0, 2) == "Q_" && myIssueNumber >= 730 && myIssueNumber <= 999 && gKasDocumentName.match("_Vshivka") == null){
                    if (app.colorSettings.workingSpaceCMYK != "ISO Web Coated"){
                       alert("Внимание! Для газеты должен использоваться провиль \"ISO Web Coated\", а установлен. — " + app.colorSettings.workingSpaceCMYK);
                    }
                 }
                 if (gKasDocumentName.substr(0, 2) == "Q_" && myIssueNumber >= 730 && myIssueNumber <= 999 && gKasDocumentName.match("_Vshivka") != null){
                    if (app.colorSettings.workingSpaceCMYK != "ImationMatchprn175lpi_avr.icc          "){
                       alert("Внимание! Для вшивки должен использоваться провиль \"ImationMatchprn175lpi_avr.icc\", а установлен. — " + app.colorSettings.workingSpaceCMYK);
                    }
                 }
                 else if (gKasDocumentName.substr(0, 4) == "Obl_"){
                    if (app.colorSettings.workingSpaceCMYK != "ImationMatchprn175lpi_avr.icc          "){
              //         alert("Внимание! Для обложки должен использоваться провиль \"ImationMatchprn175lpi_avr.icc\", а установлен. — " + app.colorSettings.workingSpaceCMYK);
                       if (confirm("Внимание! Для обложки должен использоваться провиль \"ImationMatchprn175lpi_avr.icc\", а установлен. — " + app.colorSettings.workingSpaceCMYK)) {
                          app.colorSettings.cmsSettings = "Listovaya Mashina";
                       }
                    }
                 } 
              }

              function KasinfoFromPS() {
                 var bt = new BridgeTalk;
                 bt.target = "photoshop";
                 bt.body = "app.colorSettings;"
                 bt.onResult = function(resObj) {
                    var myResult = resObj.body;
                    KascheckPsColorSettings(myResult);
                 }
                 bt.send();
              }

              function KascheckPsColorSettings(myColorSettings){
                 var myIssueNumber = parseInt(gKasDocumentName.substr(2, 3));
                 if (gKasDocumentName.substr(0, 2) == "Q_" && myIssueNumber >= 730 && myIssueNumber <= 999 && gKasDocumentName.match("_Vshivka") == null){
                    if (myColorSettings != "ISO Web Coated"){
                       alert("Внимание в Photoshop! Для газеты должен использоваться провиль \"ISO Web Coated\", а установлен. — \"" + myColorSettings + "\"");
                    }
                 }
                 if (gKasDocumentName.substr(0, 2) == "Q_" && myIssueNumber >= 730 && myIssueNumber <= 999 && gKasDocumentName.match("_Vshivka") != null){
                    if (myColorSettings != "Listovaya Mashina"){
                       alert("Внимание в Photoshop! Для вшивки должен использоваться провиль \"ImationMatchprn175lpi_avr.icc\", а установлен. — \"" + myColorSettings + "\"");
                    }
                 }
                 else if (gKasDocumentName.substr(0, 4) == "Obl_"){
                    if (myColorSettings != "Listovaya Mashina"){
                       alert("Внимание в Photoshop! Для обложки должен использоваться провиль \"ImationMatchprn175lpi_avr.icc\", а установлен. — \"" + myColorSettings + "\"");
                    }
                 } 
              }


              You can put your own stuff into the script:
              if (theItem.eventCode == "docLoaded") {
              // do your stuff here
              }

              And finally generate the plug-in.

              Kasyan
              • 4. Re: [CS3 JS] event crashes InDesign
                [Jongware] Most Valuable Participant
                Kasyan,

                Any chance you could translate that message? ;-)
                (It seems to be a warning about a 'profile'.)
                • 5. Re: [CS3 JS] event crashes InDesign
                  Kasyan Servetsky Level 5
                  The meaning of all these messages approximately the following:<br /><br />Attention! For the cover/inset/magazine should have been installed the profile called "ImationMatchprn175lpi_avr.icc"/"ISO Web Coated", but actually is installed - <i><name of the currently installed profile></i>.<br /><br />I did it for myself, so the messages are in Russian.
                  • 6. Re: [CS3 JS] event crashes InDesign
                    Kasyan Servetsky Level 5
                    P.S. I have my doubts about grammatical correctness of the previous version of translation, so here is another attempt:<br /><br />Attention! For the cover/inset/magazine, the profile called "ImationMatchprn175lpi_avr.icc"/"ISO Web Coated" should have been installed but <name of the currently installed profile goes here> is actually installed.
                    • 7. Re: [CS3 JS] event crashes InDesign
                      Level 1
                      Hi Kasyan,

                      You are an incredible help - can't wait to start testing this.

                      Best wishes from Denmark,
                      Rasmus