• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers

How to copy frames from one InDesign document to the other?

Community Beginner ,
Nov 10, 2022 Nov 10, 2022

Copy link to clipboard

Copied

Hello everyone,

 

I am trying to write a script to copy some specific frames (text/graphic) from one master indesign document to another document which has to be dynamically.

 

For example, if the master InDesign document has ten frames, i'd like to copy five specific frames based on the id and copy these frame to a new document created dynamically with the styles, alignment and all other criteria as same as in the master document. 

 

Could someone please guide me with any already available scripts , documentation or suggestions on how this can be achieved? 

TOPICS
Scripting

Views

305

Likes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Nov 10, 2022 Nov 10, 2022

Copy link to clipboard

Copied

All the documentation you need is here: https://www.indesignjs.de/extendscriptAPI/indesign-latest/#about.html

 

Specifically, look at the Applicationn, Document, Documents, TextFrame, and TextFrames APIs. You'll need a way to reference the active document and the target document (generally app.documents[0] and app.documents[1]). Then, I would name the target text frames in the master document under the Layer panel, and target them with itemByName property, then use the duplicate() methord for a text frame. A sample line would be:

 

app.documents[0].textFrames.itemByName("trgt1").duplicate(app.documents[1].pages[0]);

 

But a lot more goes into it than that. Do you have any scripting knowledge? 

Likes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Nov 10, 2022 Nov 10, 2022

Copy link to clipboard

Copied

Hi @brianp311 ,

Thank you for the link to the documentation.

I do not have any prior scripting knowledge. I am basically a .net developer, is there any SDK available? I read that there is an SDK and it's in C++. But when i try to download that from here https://developer.adobe.com/console/servicesandapis/id# , it says access denied. I already have the Adobe CC license.

Likes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Nov 10, 2022 Nov 10, 2022

Copy link to clipboard

Copied

You don't need to use C++ SDK for the use case you described. You can accomplish all what you described using JavaScript code whose DOM documentation link was supplied by @brianp311 in the post above. Using C++ SDK would be an overkill for this much work and is a very steep learning curve, so make your choices wisely.

You have two choices which according to me should be investigated first, unless you are stuck and identify that C++ is absolutely needed.

  • Extendscript, the one mentioned by Brian. It uses an old version of ECMAScript and has lots of samples shipped with InDesign installation(Scripts panel), that should get you started
  • UXP scripting, this can be used in the latest version of InDesign. This uses modern JS, but is a work in progress so may lack some functionality

-Manan

 

Likes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Nov 10, 2022 Nov 10, 2022

Copy link to clipboard

Copied

Hi @brianp311 , @Manan Joshi  I found this script and this seems to do the job, but there is one slight issue though. I want the frames to be aligned one after the other without any empty space. I think now it copies the frame with the same x, y cordinates. Basically what i am looking for is on the second image, the country frame should come right below the logo frame.master.PNGchild.PNG

var textFramesCollection = new Array();
    var myDocHeight;
    var myDocWidth;
    main();

//https://stackoverflow.com/questions/28360706/copy-a-text-frame-from-one-indesign-file-to-another-and-then-compare-there-prope
    function main()
    { 
        app.scriptPreferences.userInteractionLevel = UserInteractionLevels.NEVER_INTERACT;
        app.scriptPreferences.measurementUnit = MeasurementUnits.millimeters;
        try
        {  
            myDocHeight = app.activeDocument.documentPreferences.pageHeight;
            myDocWidth = app.activeDocument.documentPreferences.pageWidth;
            textFramesCollection = app.activeDocument.textFrames;

            var newInddDoc = app.documents.add();
            newInddDoc.documentPreferences.pageHeight = myDocHeight;
            newInddDoc.documentPreferences.pageWidth = myDocWidth;

            for( var j = 0; j < textFramesCollection.length; j++)
            {
                if(textFramesCollection[j].contents == "Logo" || textFramesCollection[j].contents == "Country")
                {
                    var myPageItem = newInddDoc.pages.item(0);
                    var newPageItem = textFramesCollection[j].duplicate(myPageItem) ;
                }
            }
            //app.activeDocument.close(SaveOptions.NO);
        }
        catch(e)
        {
            alert(e);
        }
     }

 

Likes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Nov 11, 2022 Nov 11, 2022

Copy link to clipboard

Copied

What about the Size frame where does it go, if Country frame is to be directly below Logo frame. Also, how do you define which is the first frame and where is to be placed?

-Manan

Likes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Nov 13, 2022 Nov 13, 2022

Copy link to clipboard

Copied

There would be some rules and based on those rules only specific frames would be copied to the new document. The order of the frames would be same as in the master document.

In this example, the order is 1. Logo, 2.Size 3. Country. Since size does not meet the defined rule, only 1.Logo 2.Country goes into the new document.

An additional query is, Since each frame would have some specific style defined in the master document, when we copy these frames to the new document, does the styles/properties also get copied? And are the styles embeded at the document level or at the frame level?

Likes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Nov 14, 2022 Nov 14, 2022

Copy link to clipboard

Copied

HI @Prashanthmp , Not sure if this helps, but there is the duplicate() and move() methods that lets you move and duplicate page items between documents. This duplicates the current selection to the same page in the document behind:

 

//the selected object
var s = app.documents[0].selection[0];
//its parent page offset
var pp = s.parentPage.documentOffset;
//get the page in thedocument behind with the same offset 
var tp = app.documents[1].pages[pp]
//duplicate the selection to the page
s.duplicate(tp);

 

 

Screen Shot 6.png

 

 

Dupliacte

 

 

Screen Shot 5.png

 

Likes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Nov 15, 2022 Nov 15, 2022

Copy link to clipboard

Copied

You would have to implement the logic to identify the frames and that should be easy to do. Look at the sample provided by @rob day that should take care of the InDesign API that would be needed for copying/moving the objects to the new document.

Regarding the styles being copied over, yes they are copied over with some conditions. If the style does not exist in the destination it will be copied and applied on the copied object, if it exists in the destination then the style from the destination would be applied.

Styles in InDesign are document level, there is no way to restrict a styles scope to a frame/object.

-Manan

Likes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Nov 15, 2022 Nov 15, 2022

Copy link to clipboard

Copied

Hi @Manan Joshi ,
I have been playing around with the code snippet which @rob day  shared and that works in moving the objects.

 

One additional query here is, Is there any API for creating multiple columns in page? I did not see anything at the page/page item level.

 

 

Likes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Nov 16, 2022 Nov 16, 2022

Copy link to clipboard

Copied

LATEST

The page’s margin guides are set via marginPreferences, and a text frame’s columns are set via textFramePreferences:

 

//page 1’s margin guides
app.activeDocument.pages[0].marginPreferences.properties = {columnCount:2, columnGutter:".25 in", left: ".5 in", right: ".5 in", top:".5 in", bottom: "1 in"};

//the first text frame’s columns
app.activeDocument.textFrames[0].textFramePreferences.properties = {textColumnCount: 2, textColumnGutter: ".25 in"}

 

Likes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Nov 10, 2022 Nov 10, 2022

Copy link to clipboard

Copied

Apply object styles to the frames with all relevant properties defined, copy them and paste them. 
For future use, save them in a CC Library. 

Likes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines