Separate all objects in one layer to new layers
Is it possible to separate all objects on one into their own individual layers in Indesign?
Is it possible to separate all objects on one into their own individual layers in Indesign?
Hi Brian,
I would do this spread by spread and to get stacking order right I would loop the allPageItems array of the spread in reverse. Also note, that items in that array are ignored if parent is not the spread itself.
( function()
{
app.scriptPreferences.userInteractionLevel = UserInteractionLevels.interactWithAll;
app.doScript
(
moveEveryItemToOwnLayer,
ScriptLanguage.JAVASCRIPT,
[],
UndoModes.ENTIRE_SCRIPT,
"Move every item to its own layer: Spread by Spread | SCRIPT"
);
function moveEveryItemToOwnLayer()
{
if( app.documents.length == 0 ){ return };
var doc = app.documents[0];
var spreads = doc.spreads.everyItem().getElements();
for( var n=0; n<spreads.length; n++ )
{
var currentSpread = spreads[n];
// To keep stacking order of elements, loop the array reversed or reverse the array first:
var allItemsOnSpread = currentSpread.allPageItems.reverse();
for( var a=0; a<allItemsOnSpread.length; a++)
{
// Is this a nested element? If so, do nothing and continue loop:
if( allItemsOnSpread[a].parent != currentSpread ){ continue };
// NOTE: Layer name is e.g. "spread-1-244-Rectangle" for the second spread and a rectangle with id 244.
var newLayerName = "spread"+"-"+n+"-"+allItemsOnSpread[a].id +"-"+ allItemsOnSpread[a].constructor.name ;
var newLayer = doc.layers.add({ name : newLayerName });
// We do not know what the active layer is, so always move the new layer to the top of the stack:
newLayer.move( LocationOptions.AT_BEGINNING );
// Finally assign the new layer to the page item:
allItemsOnSpread[a].itemLayer = newLayer ;
};
};
};
}() )
@Richard,
that script will ignore items on masters and will not work with items that are locked.
To add the said features is a task especially for you.
Cheers,
Uwe Laubender
( ACP )
Already have an account? Login
Enter your E-mail address. We'll send you an e-mail with instructions to reset your password.