Skip to main content
Participant
August 5, 2011
Answered

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

  • August 5, 2011
  • 1 reply
  • 477 views

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

This topic has been closed for replies.
Correct answer Mac_06

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

1 reply

Mac_06
Mac_06Correct answer
Inspiring
August 5, 2011

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

Participant
August 5, 2011

Thanks a lot. Works like a charm!

Michiel