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! 😀
Categories: InDesign Scripts
InDesign CS2, InDesign CS3, InDesign CS4, InDesign CS5
Thanks again for this script! YOU ROCK!! : )
Thanks again! 🙂
Great script! Good Job!
How can I erase the original Anchored?
Thanks!
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.
Thanks Very Much! Thanks!