Skip to main content
Mnietek1
Inspiring
August 4, 2016
Question

how to duplicate frame content to another frame

  • August 4, 2016
  • 3 replies
  • 3908 views

I'd like to duplicate content of one frame to another frame. Content is not a text. It could be a graphic or group of objects.

Is this possible?

This topic has been closed for replies.

3 replies

Community Expert
August 5, 2016

Mnietek1 wrote:

I'd like to duplicate content of one frame to another frame. …

What kind of frames are you talking about?

Source frame:

Graphic frame with nested objects?

Text frame with anchored objects?


Target frame:

Graphic frame with/without no nested objects?
Text frame with/without anchored objects?

Something else?

Regards,
Uwe

Mnietek1
Mnietek1Author
Inspiring
August 5, 2016

Thx for answers.

I mean graphic frames - not text frames.

Source graphic frame can contains just an image or group of objects.

I'd like to copy whole content of one frame to another.

I thought there is faster method than use of copy() and pasteInto()

___

sorry for my English

Community Expert
August 5, 2016

… I thought there is faster method than use of copy() and pasteInto()

Without adding something, that is not inside the source graphic frame?
Like a group object or a text frame one can anchor something to?
Unfortunately no.


Otherwise you have to sample all possible properties with their respected values of the target object, do a duplicate of the source and apply the stored values to the duplicate. Plus remove the original target.

But that would remove assumed unique properties like the id number of the object from all the id numbers of all objects in the document, would remove "private" data set by insertLabel() and 3rd party plugIns that is hard or impossible to gather…

Regards,
Uwe

Peter Kahrel
Community Expert
Community Expert
August 5, 2016

Assuming that the two frames were named on the Layers panel, you can do this:

from = app.documents[0].textFrames.item('from');

to = app.documents[0].textFrames.item('to');

from.parentStory.duplicate (LocationOptions.AFTER, to.insertionPoints[0]);

Peter

Mnietek1
Mnietek1Author
Inspiring
August 5, 2016

pkahrel napisał(-a):

Assuming that the two frames were named on the Layers panel, you can do this:

  1. from=app.documents[0].textFrames.item('from');
  2. to=app.documents[0].textFrames.item('to');
  3. from.parentStory.duplicate(LocationOptions.AFTER,to.insertionPoints[0]);

Peter

I can't get this to work.

"If you placed a group of images (any group, in fact) in a frame, then that frame is a text frame"

Are you sure? I get error "Object is invalid" when I try to access parentStory property of frame which contains group of objects...

Community Expert
August 6, 2016

Here an example with two selected objects.

The blue one is the source and contains a rectangle, the target is the yellow circle.

That's for InDesign CS5.5 or above since I am working with the order of selection with the code below.
First I selected the source, then I added the target to the selection by holding the SHIFT key and selected the target.

The script will use the mentioned app methods that work on selections.

Before:

After running the script:

Script:

You can undo the actions in one go.

Read the code, read the comments.

Note:

If the target contains anything it will be replaced by the duplicated contents of the source.
Without warning!

function main()

{

    // Minimum check, there could be way more:

    // Do nothing, if not two objects are selected:

    if(app.selection.length != 2){return};

  

    // The first selected object is the source:

    var source = app.selection[0];

  

    // Do nothing, if the source contains no object(s):

    if(source.pageItems.length == 0){return};

  

    // The second selected object,

    // that is added to the first selected one

    // is the target:

    var target = app.selection[1];

  

    // Duplicate the object inside the source

    // That would free it from the source

    var contents = source.pageItems[0];

    var dupContents = contents.duplicate();

    app.select(dupContents);

    app.cut();

    app.select(target);

    app.pasteInto();

    app.select([source,target]);

  

    // If you want to remove the object inside the source

    // do it now:

    // contents.remove();

};

app.scriptPreferences.userInteractionLevel = UserInteractionLevels.interactWithAll;

app.doScript

    (

  

    main,

    ScriptLanguage.JAVASCRIPT,

    [],

    UndoModes.ENTIRE_SCRIPT,

    "Paste Into Target | SCRIPT"

  

    );

Regards,
Uwe

Community Expert
August 5, 2016

If this is not for InDesign Server, you could use the ExtendScript methods select(), copy(), pasteInto() and move().
Just as you do this in the UI.

What is your version of InDesign?

contentPlace() would be another option, also available for InDesign Server.

InDesign and InDesign Server CS5.5 and above:

If you want to cheat a bit, you could add() a new text frame to the target graphic frame, duplicate() the contents of the source frame, move() the duplicate to the right place above the target and anchor it by insertAnchoredObject() to the added text frame.

What did you try so far with code?

Regards,
Uwe