Separate all objects in one layer to new layers

New Here ,
Jun 01, 2020 Jun 01, 2020

Copy link to clipboard

Copied

Is it possible to separate all objects on one into their own individual layers in Indesign?

TOPICS
How to , Scripting

Views

709

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

correct answers 1 Correct answer

Adobe Community Professional , Jun 08, 2020 Jun 08, 2020
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" )...

Likes

Translate

Translate
Adobe Community Professional ,
Jun 01, 2020 Jun 01, 2020

Copy link to clipboard

Copied

PageItem has a property, itemLayer, that allows you to set the item's layer. To separate everything out, you could do something like this. 

 

var allItems = app.activeDocument.layers.itemByName("Current Layer").pageItems;
for (var i = 0; i < allItems.length; i++) {
    var aNewLayer = app.activeDocument.layers.add();
    allItems[i].itemLayer = aNewLayer;
}

 

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
Adobe Community Professional ,
Jun 08, 2020 Jun 08, 2020

Copy link to clipboard

Copied

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 )

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
New Here ,
Mar 07, 2022 Mar 07, 2022

Copy link to clipboard

Copied

Hello,

 

I came across this in my search for a quick way to seperate out layers in Indesign, anyway someone can advise how to convert this into a script file for InDesign? Complete scripting noob here.

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
Adobe Community Professional ,
Mar 07, 2022 Mar 07, 2022

Copy link to clipboard

Copied

LATEST

Hi Ina,

follow the steps here:

https://www.indiscripts.com/pages/help#hd0sb2

 

Regards,
Uwe Laubender

( ACP )

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
Adobe Community Professional ,
Jun 08, 2020 Jun 08, 2020

Copy link to clipboard

Copied

Hi Richard,

alright then. My code above will not fit exactly your needs, but it is very close and could be used as a good starting point for you. Why?

 

Currently the code will move all items to a new layer.

Not only the items of a specific layer.

 

But as you can see you simply could add yet another if clause that will ask for a specific item layer.

If a page item does not qualify simply loop on with a continue and you are done.

 

Best,
Uwe Laubender

( ACP )

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