How to copy and paste indd file content into an another indd file?

1.4k views Asked by At

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.
2

There are 2 answers

0
Learning On BEST ANSWER

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;
4
Loic On

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.