2 Replies Latest reply on Sep 23, 2013 8:26 PM by DaveSofTypefi

    How do I get the path to an image?

    frameexpert Level 4

      I have an Image selected on the page. How do I get the path to the image? I see a "name" property but this just gives me a blank string. I am using CS6 and JavaScript. Thanks.

       

      Rick

        • 1. Re: How do I get the path to an image?
          frameexpert Level 4

          I found what I was looking for:

           

          var graphic = app.selection[0];

          alert (graphic.itemLink.filePath);

          • 2. Re: How do I get the path to an image?
            DaveSofTypefi Level 2

            Just bear in mind that that code could prodce a non-filePath if the graphic doesn't have an itemLink or if the itemLink is in a bad state (I've not checked but I think there are cases where changing you code to the post to the temptingly simple:

             

            myFile = File(graphic.itemLink.filePath());

             

            could cause an error or could result in something that looks like a file but isn't.

             

            Just be cautious.

             

            Usually, when I'm writing link-centric code, I normally start with the Links collection rather than the objects that might or might not have itemLinks -- at the very least it saves processing time and it also makes it a lot easier to find them.

             

            Well done finding the original answer.

             

            Dave