Home > InDesign Scripts > Copy All Anchored/Inline Objects to a New Layer

Copy All Anchored/Inline Objects to a New Layer

Few days ago on Adobe’s InDesign Scripting forum I found question about duplicating all anchored and inline objects to another layer. It’s quite simple task, and all we have to do, is to get all page items, and check item parent. If parent is Character, then it’s anchored/inline object. So, let’s take a look!🙂

First we have to get all elements. We have two options: whole document, or just current page.

Active page:

//
var myItems = app.activeWindow.activePage.allPageItems;
//

Active document:

//
var myItems = app.activeDocument.allPageItems;
//

Function:

var myDoc = app.activeDocument;
var foundObjects = Array();

for(var i = 0; i < myItems.length; i++){
    if(myItems[i].parent instanceof Character){foundObjects.push(myItems[i]);}
}

if(foundObjects.length > 0){
    try{var myDestLayer = myDoc.layers.add({name:"Anchor/Inline Duplicates"});}
    catch(_){myDestLayer = myDoc.layers.item("Anchor/Inline Duplicates");}
    for(var i = 0; i < foundObjects.length; i++){
        var newDuplicate = foundObjects[i].duplicate(myDestLayer);
        newDuplicate.geometricBounds = foundObjects[i].geometricBounds;
        try{newDuplicate.graphics[0].geometricBounds = foundObjects[i].graphics[0].geometricBounds;}catch(_){}
    }
}

That’s it!

Have fun!😀

  1. Theresa
    September 17, 2010 at 00:16

    Thanks again for this script! YOU ROCK!! : )

    • September 17, 2010 at 00:23

      Thanks again!🙂

  2. Herbert
    December 12, 2011 at 10:39

    Great script! Good Job!
    How can I erase the original Anchored?

    Thanks!

    • December 12, 2011 at 11:53

      Thanks!

      To delete original anchored object, change line 14 to this:

      try{foundObjects[i].remove(); newDuplicate.graphics[0].geometricBounds = foundObjects[i].graphics[0].geometricBounds;}catch(_){}

      Hope that helps.

  3. Herbert
    December 12, 2011 at 17:28

    Thanks Very Much! Thanks!

  1. No trackbacks yet.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: