6 Replies Latest reply on May 21, 2014 9:02 AM by Harbs.

    Place Image Error

    Gavin1985 Level 1

      I've created a script that grabs a JPG, places it so I can get the dimensions, then creates a batch file for some other software to make it into a TIF packshot. I then place the TIF in place of the JPG (I know that this could be more streamlined). It also makes a couple of visits to some Photoshop droplets in the batch file too.

       

      However,every so often - maybe every 30 images or so, it throws up a placing error when placing the TIF, stating "Error: Either the file does not exist, you do not have permission, or the file may be in use by another application." I put a loop in to wait a second then try again, and I still get the same error so it's not down to Photoshop not releasing the file quickly enough - I've also tried it on a 10 second delay. It occurs sporadically, and if I kill the script and place the file manually, it places fine. I've even tried putting in a break point in the catch function, cycling through the code manually, closing Photoshop completely (which is the last program to access the file), and it still won't place. My link is correct, there's nothing accessing the file, there is seemingly no problem with it at all. I've even tried modifying the file in Photoshop and it saves fine proving that it is not open elsewhere, but the file still won't place. It's almost like InDesign has made a decision that it doesn't like the file on this occasion. If I kill the script and re-run, it will place fine the next time around and another image will go wrong.

       

      The code I'm using to place is:

                                 for(counter = 0; counter < 10; counter++)

                                  {

                                      try

                                      {

                                          imageToPlace = new File(fileLocation+"//images//"+tempEAN+".tif");

                                          gbImage[0].place(imageToPlace);

                                          counter = 10;

                                      }

                                      catch(error)

                                      {

                                          $.writeln(imageToPlace.modified)

                                          $.writeln(error);

                                          $.sleep(1000);

                                      }

                                  }

                               }

       

      If it's helpful, I'm running this on the company network, on a windows share from a windows 8.1 machine using InDesign CC 64 bit. It is definitely the place that is throwing the error as the "new File()" bit is working fine. I get the modified date of the file in the catch fine too.

       

      Any help here would be very much appreciated.

        • 1. Re: Place Image Error
          Harbs. Level 6

          It looks like you are placing the same image multiple times.

           

          I'm not sure, but I'm guessing that InDesign is the application that's not finished with the image (probably generating a preview or something).

           

          In this situation, there's a couple of alternates to place()ing the image file:

          1) You can generate a snippet of the placed file and place that.

          2) You can place it once and then duplicate() the image to the other location.

           

          I would probably go with option #2 which has the advantage of probably being more performant since the preview does not need to be recreated every time.

           

          HTH,

          Harbs

          • 2. Re: Place Image Error
            Harbs. Level 6

            Another option is to use IDLE events to continue the process when you get an error. sleep() will not help because it keeps InDesign in a frozen state and InDesign cannot release the file when it's in such a state. Using an IDLE event allows InDesign to finish whatever it needs to before you go on.

             

            You also don't say whether this is Windows or Mac. I'd guess Windows if I had to. I've seen some weird file release issues on Windows that I haven't seen on Mac...

             

            Harbs

            • 3. Re: Place Image Error
              Gavin1985 Level 1

              Thanks for the response Harbs,

               

              The for loop is only in place because I thought that Photoshop was being tardy releasing file. The exception throws the first time I try to place the TIF.

               

              However, your comment about previews seems to be bearing some fruit. I realized that I have always had a Windows Explorer window of the image folder open, so I think that it is the thumbnail generation there that is causing the problem. I've closed the window and I'm quite deep into the batch of images now and so far I'm error free :-) Thanks for the hint.

               

              However, it doesn't answer why Javascript still thought the file was being accessed, long after Explorer had released it - As I say, I could manipulate the file name and edit the image in Photoshop when I had the explorer window open, which I wouldn't be able to do if the horrid Windows 7/8 Explorer preview system was still using it. Does Javascript need to refresh somehow? I'm trying to make this script restriction free for my colleagues, and I really don't want them coming across errors because they have left the folder they are working in open in explorer.

              • 4. Re: Re: Place Image Error
                Laubender Adobe Community Professional & MVP

                @Gavin – I'm hesitating to suggest this, don't know if it will work or on the contrary will do damage:

                 

                How about closing the file explicitly right after setting the variable imageToPlace?

                 

                imageToPlace = new File(fileLocation+"//images//"+tempEAN+".tif");
                if(imageToPlace.exists){imageToPlace.close()};
                else{ /*check alternative ways to proceed*/ }
                

                 

                Uwe

                • 5. Re: Place Image Error
                  Gavin1985 Level 1

                  Thanks Laubender,

                   

                  I've dropped in your suggestion, but sadly it didn't work. However, it has proved my hypothesis that it's having the Explorer window open that causes the issue.

                   

                  I also tried changing the image in imageToPlace to something else, then change it back again, but that hasn't worked either.

                  • 6. Re: Place Image Error
                    Harbs. Level 6

                    It's possible that InDesign is not being updated about the file being made available.

                     

                    I'd try using an IDLE event to continue after you get an error.