1 Reply Latest reply on Oct 31, 2014 1:33 AM by bastieneichenberger

    includes in BridgeTalk object

    bastieneichenberger Level 1

      Hi all, I'm writing a module to execute scripts from InDesign to Photoshop. I used bridge talk and the module works until now I would like to include a library in the photoshop script but this script in executed in the photoshop context so I cannot use relative path … Has anyone an other idea to do this cleaner?

       

      In advance thanks you for your help!

       

       // crop this link
                  H.Gateway.call_app(
                      'photoshop',
                      crop_in_photoshop,
                      [current_link.filePath, top_left_corner, bottom_right_corner, graphic.absoluteHorizontalScale, graphic.absoluteVerticalScale, resolution, 'ResampleMethod.NONE'],
                      100
                  );
      

       

      Here I have to write the path with absolute notation

      function crop_in_photoshop (file_path, top_left_corner, bottom_right_corner, horizontal_scale, vertical_scale, resolution, resample_method) {
          //@include "/Applications/MAMP/htdocs/extendscript-library.org/lib/photoshop/photoshop-lib.jsx"
          try {
              PS.Config.init();
              PS.Application.open(file_path);
              var ps_doc = app.activeDocument;
      
      
              PS.Document.Resize.resampling(ps_doc, file_path, horizontal_scale, vertical_scale, resolution, resample_method);
      
      
              bounds = [top_left_corner.x, top_left_corner.y, bottom_right_corner.x, bottom_right_corner.y];
              ps_doc.crop(bounds);
              ps_doc.save();
          }
          catch (ex) {
              throw {
                  name: 'Error',
                  message: ex.message,
                  fileName: $.fileName,
                  lineNumber: $.line
              };
          }
          finally{
              PS.Application.restore();
          }
      }
      

       

      The Bridge Talk module

       my.call_app = function (app, function_to_execute, args, timeout) {
              var error_message;
              var result;
              var complete;
      
      
              var bt = new BridgeTalk();
              bt.target = app;
      
      
              if (args) {
                  /**
                   * build a string representation of the function
                   *  (function hello(a, b)
                   *      my code;
                   *  }).apply(this, [])
                   */
                  bt.body = function_to_execute.toSource() + '.apply(this, ' +  args.toSource() +');';
              }
              else {
                  bt.body = function_to_execute.toSource() + '();';
              }
      
      
              bt.onError = function (ex) {
                  error_message = ex.body;
              };
      
      
              bt.onResult = function (response) {
                  result = response.body;
                  complete = true;
              };
      
      
              bt.send(timeout); // we have to wait the response of the other software
      
      
              // if an error occurred throw it
              if (error_message) {
                  throw {
                      name: 'Error',
                      message: error_message,
                      fileName: $.fileName,
                      lineNumber: $.line
                  };
              }
              // if the onResult function isn't complete, the timeout exceeded
              if (!complete) {
                  throw {
                      name: 'TimeoutError',
                      message: 'exceeded timeout of ' +  timeout + ' seconds',
                      fileName: $.fileName,
                      lineNumber: $.line
                  };
              }
      
      
              // else return the result or null
              return result || null;
      
      
          }