8 Replies Latest reply on May 31, 2015 9:49 AM by psycho.bunneh

    Help converting a simple Illustrator script to InDesign

    psycho.bunneh

      A while ago CarlosCanto posted a nice simple script that does exactly what I need, except it's for Illustrator. Can someone help me get it to run in InDesign?

       

      Re: Is there a way to create a keyboard shortcut to relink images in Illustrator CS5?

      1. #target Illustrator 
      2.  
      3. // script.name = relinkAllSelected.jsx; 
      4. // script.description = relinks all selected placed images at once; 
      5. // script.required = select at least one linked image before running; 
      6. // script.parent = CarlosCanto // 7/12/11; 
      7. // script.elegant = false; 
      8.  
      9. var idoc = app.activeDocument; 
      10. sel = idoc.selection; 
      11. if (sel.length>0
      12.      { 
      13.           var file = File.openDialog ("open file"); 
      14.           for (i=0 ; i<sel.length ; i++ ) 
      15.                { 
      16.                    if (sel[i].typename == "PlacedItem"
      17.                         { 
      18.                             var iplaced = sel[i]; 
      19.                             iplaced.file = file; 
      20.                          } 
      21.                } 
      22.      } 
      23. else 
      24.      { 
      25.           alert("select at least one placed item before running"); 
      26.      } 
        • 1. Re: Help converting a simple Illustrator script to InDesign
          Larry G. Schneider Adobe Community Professional & MVP

          Ask in the ID Scripting forum or do a search there for Kasyan, Relink

          • 2. Re: Help converting a simple Illustrator script to InDesign
            pixxxel schubser Level 5

            Hi psycho.bunneh,

            try this one:

            #target InDesign
            
            // script.original.name = relinkAllSelected.jsx;  // for Illustrator
            // script.converted.name = replaceAllLinks.jsx; // for InDesign
            // script.description = relinks all images at once;
            // script.parent = CarlosCanto // 7/12/11;
            // script.elegant = false;
            
            // script.converted = pixxxelschubser // 31/05/15;
            // no selection required;
            // but there are still much to be done;
            
            var aDoc = app.activeDocument;
            allLinks = aDoc.links;
            if (allLinks.length>0) {
                var file = File.openDialog ("open file");
                for (i=0 ; i<allLinks.length ; i++ )
                {
                    /*if (sel[i].typename == "PlacedItem")
                        {
                        var iplaced = sel[i];
                        iplaced.file = file;
                        } */
                    allLinks[i].relink(file);
                    allLinks[i].update();
                    }
                } else {
                    //alert("select at least one placed item before running");
                    alert("there are no links in your document");
                    }
            

             

            Have fun

             

            • 3. Re: Help converting a simple Illustrator script to InDesign
              psycho.bunneh Level 1

              This is super close but it changes every link and I'd like to just change the ones I have "highlighted" or selected like the first script does. I thought if I just changed allLinks = aDoc.links;  to allLinks = aDoc.selection; that it would fix it but it just broke everything.

              • 4. Re: Help converting a simple Illustrator script to InDesign
                psycho.bunneh Level 1

                I did a lot of Googling before I posted and came across a lot of Kasyan's scripts that addressed relink issues. However, all the scripts of his that I could find were either for updating paths or updated links to altered files (i.e. they all seem to search for a file with the same name) I don't need to update links I need to change them completely.

                 

                I did not realize there was a scripting sub-forum. I will post this there as well. Thanks!

                • 5. Re: Help converting a simple Illustrator script to InDesign
                  pixxxel schubser Level 5

                  Hmmh?

                  Why you don't use the Links-palette (in the UI) for this? Normally in ID you don't need a script for this requirements.

                  • 6. Re: Help converting a simple Illustrator script to InDesign
                    psycho.bunneh Level 1

                    I'm using this to lay out business cards onto large sheets of paper for printing. I might need the first 20 cards to be Jim's and the next 10 to be Susan's and the last 10 to be Burt's (or whatever). The thing is that those numbers aren't always the same so I need to be able to change how many I have selected (or else I could just re-link all of one kind of image). So I need to be able to hand select some images and relink them. I CAN use the UI, that's how I'm doing it currently but when you select the first 20 cards, it prompts you relink each of the 20 selected links individually. Then you have to do it again for the next 10 and so on. The result is that I'm individually linking 40 images each time and it takes fooooreeeeveeeer. I want to be able to batch relink SOME images but not all. Did that make sense?

                    • 7. Re: Help converting a simple Illustrator script to InDesign
                      pixxxel schubser Level 5

                      Does this better works for you?

                      #target InDesign
                      
                      // script.original.name = relinkAllSelected.jsx;  // for Illustrator
                      // script.converted.name = relinkAllSelected_forID.jsx; // for InDesign
                      // script.description = relinks all selected images at once;
                      // script.parent = CarlosCanto // 7/12/11;
                      // script.elegant = false;
                      
                      // script.converted = pixxxelschubser // 31/05/15;
                      // 
                      // but there is still much to be done;
                      
                      var aDoc = app.activeDocument;
                      theSel = aDoc.selection;
                      if (theSel.length>0) {
                          var file = File.openDialog ("open file");
                          for (i=0 ; i<theSel.length ; i++ )
                          {
                              alert(theSel[i].graphics[0].constructor.name)
                              theSel[i].graphics[0].itemLink.relink(file);
                              theSel[i].graphics[0].itemLink.update();
                              }
                          } else {
                              alert("select at least one image before running");
                              }
                      

                       

                      Be sure, that all selected Items are images – otherwise the script snippet fails.

                      • 8. Re: Help converting a simple Illustrator script to InDesign
                        psycho.bunneh Level 1

                        It's perfect! You're the best! :-D I am so stoked, you have no idea.