1 Reply Latest reply on Jul 2, 2017 6:59 AM by Trevorׅ

    Indesign scripting relink Graphic.itemLink to external web url

    hladdha123 Level 1

      Hi,

       

      I have a simple function in InDesign ESTK script to link images with external web urls like this -

       

      function relink_converted_image(filename, path, converted_label) {
          try {   
              var results = app.documents.item(0).allGraphics;
              var found_links = [];
              var label = converted_label.split('__doc=').pop();
              for(var i=0; i < results.length; i++) {
                  if(results[i].itemLink != null) {
                      var result_label = results[i].itemLink.label;                
                      if(result_label && result_label == label) {
                          logMe('found id - ' + label);
                          var file_web = File(path);
                          var newLink = results[i].itemLink.relink(file_web);
                          found_links.push(results[i].itemLink.filePath);
                          try {
                              results[i].itemLink['label'] = converted_label;
                          } catch(e) {
                              logMe(e.toString());
                          }
                          try {
                              newLink['label'] = converted_label;
                          } catch(e) {
                              logMe(e.toString());
                          }
                      }
                  }
              }
              return JSON.stringify({err: 0, data: found_links});
          } catch(e) {
              return JSON.stringify({err: -1, data: e});
          }
      }
      

       

      the sample input that I am passing is -

      relink_converted_image("cfc7cfdf-bc59-4dfc-90af-bfa4d74618da__doc=07012017_comp__id=0xUKYw8.PNG","http://localhost:3000/prod_equation_images/cfc7cfdf-bc59-4dfc-90af-bfa4d74618da__doc=07012017_comp__id=0xUKYw8.PNG", "cfc7cfdf-bc59-4dfc-90af-bfa4d74618da__doc=07012017_comp__id=0xUKYw8.PNG");
      

      and all my images are linked and labelled uniquely locally.

      Now, I am not able to relink the found linked graphic with a asset on a different local server with -

      File('web_asset_url')
      

      or

      results[i].itemLink.relink('web_asset_url')
      

      Are there any other ways to add dynamic link assets hosted externally with InDesign ?