2 Replies Latest reply on Apr 17, 2009 9:23 AM by smantscheff

    How to select a rectangle which was inserted from the clipboard?

    smantscheff

      For a batch run of inserting images I'm facing this situation:

      There is a document with a lot of paragraphs containing an image file name like "034.tif".

      I have a rectangle which has the exact size and style how the images must be placed.

      I copy this to the clipboard.

      Then I run a script which seeks for image file names and replaces them with the contents of the clipboard (the desired rectangle).

       

      If the script stops here, the cursor is placed directly after the just inserted rectangle.

      How can the script select the rectangle left of the cursor so that the image is inserted into the rectangle instead of after it?

       

      The script now looks like that:

       

      // copy the desired rectangle to the clipboard manually

      app.changeGrepPreferences = NothingEnum.nothing;
      app.findGrepPreferences.findWhat = "002.tif";
      app.changeGrepPreferences.changeTo = "~c";
      var myPlace = app.changeGrep();

      // here is the point where I need to select the rectangle which changeGrep just inserted

      myPlace[0].place('002.tif', false);

        • 1. Re: How to select a rectangle which was inserted from the clipboard?
          Dave Saunders Level 4

          Your script as written will replace all instances of your text in all opened documents with the contents of the clipboard, so "selecting" the result could be problematic. However, you can get an array of references to the result, like this:

           

          var myPlaces = app.changeGrep();

          for (var j = 0; myPlaces.length > j; j++) {

               var myRect = myPaces[j].rectangles[0]; // assumes contents of clipboard was indeed a rectangle

               var myRect.place(('002.tif', false);

          }

           

          Although I'm dubious that you can just pass the name of the tif to the place command. I'd pass a full file reference myself.

           

          The point here is that the changeGrep command returns an array of text references to the changed text. Each of your changed texts (even if there's only one) is a character containing an inline or anchored rectangle, which is referenced as the first member of the collection of rectangles parented by the character.

           

          Dave

          • 2. Re: How to select a rectangle which was inserted from the clipboard?
            smantscheff Level 1

            Works like a spell. Thank you ever so much. Someday I'll even understand the object model.

            And yes, obviously you can pass file names instead of file objects. At least it works in this case.