3 Replies Latest reply on Nov 29, 2012 12:12 PM by Ben Applegate

    "Object is invalid" after three loops

    Ben Applegate

      This script is placing objects on pages (in reverse order, as it happens). It works correctly for three pages, then stops and gives me the following error:

       

      Object is invalid

      Line: 15

      Source: img = doc.pages[pageNo].place(fileList[a]);

       

      I have no clue why, so any help would be very appreciated.

       

      var doc = app.activeDocument;

      var totalPages = parseInt(app.activeWindow.activePage.name);

      var inFolder = Folder.selectDialog("Please select folder to process");

      if(inFolder != null){

      var fileList = inFolder.getFiles(/\.(tif)$/i);

       

      for(var a = 0 ;a < fileList.length; a++){

       

      if(fileList[a] instanceof File){

      var fileString = fileList[a].name.split("_",1);

      var fileNo = parseInt(fileString);

      var pageNo = totalPages - fileNo;

      img = doc.pages[pageNo].place(fileList[a]);

      imgFrame = img[0].parent;

      var Bound = imgFrame.geometricBounds;

      var h = Bound[2]-Bound[0];

      var scalePercent = 7.75/h;

      var imgMatrix = app.transformationMatrices.add();

      imgMatrix = imgMatrix.scaleMatrix(scalePercent, scalePercent);

       

      if(fileNo[0]%2 == 0){

      imgFrame.transform(CoordinateSpaces.PASTEBOARD_COORDINATES,AnchorPoint.topRightAnchor,imgM atrix);

      } else {

      imgFrame.move(["-.125in", "-.125in"]);

      imgFrame.transform(CoordinateSpaces.PASTEBOARD_COORDINATES,AnchorPoint.topLeftAnchor,imgMa trix);

      }

       

      }

      }

      };