1 Reply Latest reply on Oct 13, 2010 12:00 AM by Yuliaart

    Bridge Talk in InDesign CS4 js

    Yuliaart Level 1

      Hi,

       

      I need to adjust the script to open in Ph and re-save as png 2 page pdf liked file in indd. Right now the script does everything, but it re-saves and re-links first page of the pdf onto both indd's pages only. And I need it to place first png (from first page of the pdf) into 1st indd's page, and second png file (from second page of the pdf) into 2nd indd's page.

       

      I hope it's not too confusing.

       

       

      #target indesign
       
      var myDoc = app.activeDocument;
      var myFolder = Folder.selectDialog ("Select the output folder for PNG images");
       
      SetDisplayDialogs("NO");
      OpenFiles();
      SetDisplayDialogs("ALL");
      UpdateAllOutdatedLinks();
      alert("Done");
       
      function OpenFiles(){
           for (var i = myDoc.links.length-1; i >= 0; i--) { // process links collection backwards since it's changing! 
                var myLink = myDoc.links[i];
                  
                if (myLink.linkType != "Portable Network Graphics (PNG)"){
                     var myImage = myLink.parent;
                     var myImagePath = myLink.filePath;
                     var myImageFile = new File(myImagePath);
                     var myNewPath =  myFolder.absoluteURI + "/" + GetFileNameOnly(myImageFile.name) + ".png";
                     CreateBridgeTalkMessage(myImagePath, myNewPath);
                     Relink(myLink, myNewPath);
                }
           }
      }
      //--------------------------------------------------------------------------------------------------------------
      function CreateBridgeTalkMessage(myImagePath, myNewPath) {
           var bt = new BridgeTalk();
           bt.target = "photoshop";
           var myScript = ResaveInPS.toString() + "\r";
           myScript += "ResaveInPS(\"" + myImagePath + "\", \"" + myNewPath + "\");";
           bt.body = myScript;
           bt.onResult = function(resObj) {} 
           bt.send(100);
      }
      //--------------------------------------------------------------------------------------------------------------
      function ResaveInPS(myImagePath, myNewPath) {
           try {
                 var myPsDoc = app.open(new File(myImagePath));
                   if (myPsDoc.mode == DocumentMode.CMYK) {
                          myPsDoc.changeMode(ChangeMode.RGB);
                     }
                 var docName = myPsDoc.name;
      
                var myPNGSaveOptions = new PNGSaveOptions();
                myPNGSaveOptions.interlaced = false; // or true
                myPsDoc.saveAs(new File(myNewPath), myPNGSaveOptions, true);
                myPsDoc.close(SaveOptions.DONOTSAVECHANGES);      
           }
           catch (err) {
                try {
                     app.activeDocument.close(SaveOptions.DONOTSAVECHANGES);
                }
                catch (err) {}
           }
      }
      //--------------------------------------------------------------------------------------------------------------
      function Relink(myLink, myNewPath) {
           var newFile = new File (myNewPath);
           if (newFile.exists) {
                var originalLinkFile = new File(myLink.filePath);
                myLink.relink(newFile);
                
                try { // for versions prior to 6.0.4
                     var myLink = myLink.update();
                }
                catch(err) {}
           }
      }
      //--------------------------------------------------------------------------------------------------------------
      function SetDisplayDialogs(Mode) { // turn on-off DialogModes in PS -- don't want to see the open file dialog while the script is running
           var bt = new BridgeTalk;
           bt.target = "photoshop";
           var myScript = "app.displayDialogs = DialogModes." + Mode + ";";
           bt.body = myScript;
           bt.send();
      }
      //--------------------------------------------------------------------------------------------------------------
      function UpdateAllOutdatedLinks() {
           for (var myCounter = myDoc.links.length-1; myCounter >= 0; myCounter--) {
                var myLink = myDoc.links[myCounter];
                if (myLink.status == LinkStatus.linkOutOfDate) {
                     myLink.update();
                }
           }
      }
      //--------------------------------------------------------------------------------------------------------------
      function GetFileNameOnly(myFileName) {
           var myString = "";
           var myResult = myFileName.lastIndexOf(".");
           if (myResult == -1) {
                myString = myFileName;
           }
           else {
                myString = myFileName.substr(0, myResult);
           }
           return myString;
      }
      
      

       

      Thank you very much for your help.

      Yulia

        • 1. Re: Bridge Talk in InDesign CS4 js
          Yuliaart Level 1

          I think this will make more sense:

           

           

          I need to adjust the script to open in Ph and re-save as png 2 page pdf  liked in indd. Right now the script does everything, but it  re-saves and re-links first page of the pdf onto both indd's pages only.  And I need it to place first png (from first page of the pdf) into 1st  indd's page, and second png file (from second page of the pdf) into 2nd  indd's page.

           

          See the script in the 1st post.

           

          Thank you very much.

          Yulia