4 Replies Latest reply on Sep 21, 2017 7:36 AM by Kasyan Servetsky

    Script for Linking Images with Url's from a Spreadsheet

    meganm24796850 Level 1

      Hey all,

       

      I'm fairly new to using scripts in InDesign, but I need to write one specifically for a catalog I'm working on. I have successfully imported all of the product information and images from a .csv file using data merge. Each page has 6 products, and each product takes up one row with four columns. I am needing to make a digital version of this catalog that allows the customer to click on the image of any product and have it lead them to that product on the company website.

       

      I have all of the product urls in a .csv spreadsheet that are sorted accordingly to each product, but I am at a loss on how to write a script that will pull these urls from the spreadsheet and link them to the product images in the document.

       

      I am using InDesign CC 2017, and Microsoft Excel for Mac Version 15.33

       

      If anyone is able to help or even remotely point me in the right direction on what to do it would be greatly appreciated!!

       

      All the best,

       

      Megan

        • 1. Re: Script for Linking Images with Url's from a Spreadsheet
          Kasyan Servetsky Level 5

          I think the Auto hyperlink script (by Nobrainer Scripting) may come in handy to you. You can save the csv-file as txt leaving only product names and URLs separated by tabs.

          • 2. Re: Script for Linking Images with Url's from a Spreadsheet
            Liphou Level 1

            Hello here is a code that I started to regroup because I will also be led to do the same

            Bonjour voici un code que j'ai commence à regroupé car je serai aussi amené à faire la même chose

             

            var imgs = app.activeDocument.allGraphics;   
             
            
            
             $.writeln (imgs.length);
            
             for (var i = 0; i < imgs.length; i++) {
                   
            // imgs[i].verticalScale = 92;
                    
            //imgs[i].horizontalScale = 92;
                    
            //imgs[i].fit(FitOptions.FRAME_TO_CONTENT);
                   
            // imgs[0].parent.appliedObjectStyle = "LeStyle";
                   
            // imgs[0].parent.applyObjectStyle( "LeStyle" );
                   
            $.writeln(imgs[i].parent.appliedObjectStyle.name);
                   
            $.writeln(imgs[i].itemLink.filePath);//  = app.activeDocument.objectStyles.itemByName("LeStyle"); // Faire controle
                   
            $.writeln(imgs[i].itemLink.name);//  = app.activeDocument.objectStyles.itemByName("LeStyle"); // Faire controle
                
            try{
                
            myHyperlinkURL = app.activeDocument.hyperlinkURLDestinations.add('http://www.apple.com');
                
            myHyperlinkSource = app.activeDocument.hyperlinkPageItemSources.add(imgs[i].parent);
                
            myHyperlink= app.activeDocument.hyperlinks.add(myHyperlinkSource,myHyperlinkURL);
                
            myHyperlink.visible=false;
                
            }
                    
            catch(myError){
            
            }
            
                
                  
             
            
               }//
            
            • 3. Re: Script for Linking Images with Url's from a Spreadsheet
              monicam90436292 Level 1

              Hi Kasyan,
              This script sounds perfect for the project I'm working on! I'm having some issues making it work though and was hoping you could help. If I'm keeping the txt filed named the exact same do I need to change anything in the script?
              Thanks!
              Monica

              • 4. Re: Script for Linking Images with Url's from a Spreadsheet
                Kasyan Servetsky Level 5

                Hi Monica,

                 

                No, you don't have to interfere in the script; the user is supposed to edit the txt-file only.

                However, if your project has some specific requirements, the script may need some adjustments.

                 

                Regards,
                Kasyan