Hello folks,
The above code works great, but for some reason it does not process all the images in the document. After creating a link for the first 15/20 images, it stops. I do not get any error messages either. I created alerts in the java script trying to figure out a pattern but so far no luck. Any suggestion on why the script might not be processing all the images in the document or how best I can debug and fix the problem.
Any help or suggested changes to the code would be greatly appreciated.
Thank you,
Phani
I can't test the script at the moment, but looking at it, I do notice that the entire for loop is within a try-catch. That means that if it encounters an error, it stops processing any more graphics. There may be a good reason for this, but I think you could just move the try-catch into the for loop, so it can catch any individual linking error without stopping completely. Something like this:
var myDoc = app.activeDocument;
var myGr = app.activeDocument.allGraphics;
alert(myGr.length)
for(i=0; i<myGr.length; i++)
{
try{
var myGrName = String(myGr.itemLink.name);
var mySplitName = myGrName.split(".")[0];
app.select(myGr.parent)
myHyperlinkPageItemSource = app.activeDocument.hyperlinkPageItemSources.add(app.selection[0])
var myHyperlinkURLDestination = app.activeDocument.hyperlinkURLDestinations.add("https://www.testabc.com/productdetails.aspx?itemnum=" + String(mySplitName)));
var myHyperlink = app.activeDocument.hyperlinks.add(myHyperlinkPageItemSource, myHyperlinkURLDestination, {name: "https://www.testabc.com/productdetails.aspx?itemnum=" + String(mySplitName)})
} catch(e){}
}
alert("Process Completed")
The forum's syntax highlighting is giving me a hard time, but I would probably throw an "alert(myGrName)" into those catch brackets so you can begin to try to figure out where it's erroring out (if that is indeed the problem).
Another thought is that, if there's a chance of multiple images with the same number, you might want to have your hyperlinkURLDestination check for an already existing destination before adding a new one.