1

I'm newbie in indesign scripting stuffs.So I apologise as I couldn't post my trials.

Objective:
I have an indd document which will have figure caption,label etc. I need to copy content(figure which is editable) from other indd file to this document where related figure label exists.

For example:
sample.indd

Some text   
Fig.1.1 caption
some text

I need to copy the content of figure1.indd and paste into the sample.indd document where Fig.1.1 string exists and so on. Now I'm doing it manually. But am supposed to automate this.

So, I need some hint how to acheive it using extendscript?

I have found something like below to do this, but I don't have any clue to develop it further and also am not sure whether this approach is correct to get my result. Pls help me

myDocument=app.open(File("file.indd"),false);  //opening a file to get the content without showing.
myDocument.pages.item(0).textFrames.item(0).contents="some text"; 
//here I could set the content but I don't knw how to get the content

// ?????? Then I have to paste the content into active document.
Learning
  • 848
  • 1
  • 9
  • 32

2 Answers2

2

I found the script for my requirement.

var myDoc = File("sample.indd");//Destination File  
var myFigDoc = File("fig.indd");//Figure File  
app.open(File(myFigDoc));  
app.activeDocument.pageItems.everyItem().select();  
app.copy();  
app.open(File(myDoc));  
app.findGrepPreferences = app.changeGrepPreferences = null;  
app.findGrepPreferences.findWhat = "FIG. 1.1 ";//Figure caption text  
//app.findGrepPreferences.appliedParagraphStyle = "FigureCaption";//Figure Caption Style  
myFinds = app.activeDocument.findGrep();  
for(var i=0;i<myFinds.length;i++){  
    myFinds[i].insertionPoints[0].contents="\r";  
    myFinds[i].insertionPoints[0].select();  
    app.paste();  
}  
app.findGrepPreferences = app.changeGrepPreferences = null;
Learning
  • 848
  • 1
  • 9
  • 32
0

If acceptable for you, you can place an indesign file as link (place…). So a script could try to catch the "fig…" strings and do the importation. Have a look at scripts that use finGrep() and place() command.

Loic
  • 2,173
  • 10
  • 13
  • If I place a link of file into the document,how will i get my output? Manually am doing like, open a indd file.select all , copy and paste it into the target indd file. – Learning Jun 25 '15 at 12:18
  • i need to copy the content of a file rather than a file – Learning Jun 25 '15 at 12:38
  • If I do like this, `myTextFrame.place(File("fig.indd"));` it places like an figure (non editable without frames). If i select all and do copy and paste only then it places as editable fig in the target. – Learning Jun 26 '15 at 11:57
  • I understand. You could as well use app.select()/copy()/paste()… – Loic Jun 26 '15 at 16:49