3 Replies Latest reply on Aug 5, 2011 4:37 AM by [Jongware]

    [JS ID CS5] I fail to use move instead of copy

    Michiel Koers Level 1

      Hello everyone,

       

      A little while ago I started working on my first InDesign script. It is a script that places a Word file in an InDesign-file and then searches for tags. Text between these tags needs to be moved to certain text frames already in the InDesign file. So far things are working great. However, I read on this forum that it is better and faster to use the move function instead of using select, cut and paste to move text to a different text frame. I can't get this to work.

       

      This is the working script i use to copy/paste some text to the appropiate frames.

       

      app.findGrepPreferences.findWhat = "<paragraaf1>.+</paragraaf1>";
      var gevondenTag1 = myDocument.findGrep();

      app.cut(app.selection = gevondenTag1);
      app.select(bestaandTextFrame1.parentStory.insertionPoints.item(0));
      app.paste();

       

      As I said, this works ok. But since i want to run this script on about 600 Word files, speed is an important factor. So i tried to use move.

      The script I wrote and doesn't work is this:

       

      app.findGrepPreferences.findWhat = "<paragraaf1>.+</paragraaf1>";
      var gevondenTag1 = myDocument.findGrep();
      bestaandTextFrame1.parentStory.insertionPoints.item(0).move(LocationOptions.before, gevondenTag1)

       

      Does anyone have an idea what i'm doing wrong? How can I get this to work?

       

      Thanks in advance!

      Michiel Koers,

      Mediadesigner at M-effect

      www.meffect.nl

        • 1. Re: [JS ID CS5] I fail to use move instead of copy
          Mac_06 Level 2

          Though not tested... but should work.

           

          var myDocument = app.activeDocument
          var bestaandTextFrame1 = app.activeDocument.textFrames.itemByName("Test")
          app.findGrepPreferences.findWhat = "<paragraaf1>.+</paragraaf1>";
          var gevondenTag1 = myDocument.findGrep();
          app.selection=gevondenTag1
          app.selection[0].move(LocationOptions.before, bestaandTextFrame1.parentStory.insertionPoints.item(0))
          

           

          Mac

          • 2. Re: [JS ID CS5] I fail to use move instead of copy
            Michiel Koers Level 1

            Thanks a lot. Works like a charm!

             

            Michiel

            • 3. Re: [JS ID CS5] I fail to use move instead of copy
              [Jongware] Most Valuable Participant

              Mac_06 wrote:

               

              var gevondenTag1 = myDocument.findGrep();
              app.selection=gevondenTag1
              app.selection[0].move(LocationOptions.before, bestaandTextFrame1.parentStory.insertionPoints.item(0))
              

               

               

              Note that there is no need to 'move' the gevondenTag1 array into app.selection.

               

              findGrep returns an array of found objects, and you can use that immediately in the next line:

               

               

              var gevondenTag1 = myDocument.findGrep();
              gevondenTag1[0].move(LocationOptions.before, bestaandTextFrame1.parentStory.insertionPoints.item(0))
              

               


              (This also gives you a hint on how to use a for..loop to iterate over all found items, not just the first one.)

              1 person found this helpful