• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
1

Separate content from a single layer to multiple layers

Community Beginner ,
Aug 19, 2019 Aug 19, 2019

Copy link to clipboard

Copied

I have an InDesign page that has many elements that are all on one layer. Is there an easy way or script I can use to move each individual element to its own layer?

Here is a bit more of an explanation of why I need this:

1. I understand this is not what InDesign is intended for, however I am in this situation and looking for an easy fix.

2. The screen shot below is of a website page design that was created in InDesign. I am showing the 1 and only layer in the file with its contents exposed in the layer panel. What I would like to do is have each one of these elements on a separate layer.

3. The reason I want to do this is because I am then going to use a scrip that will export the page as a layered PSD file based on the layers in InDesign. I have multiple pages I have to do this for and it is time consuming moving each element to an individual layer one by one.

I'm wondering if there is a script available that will take the contents of the layer and move each item out to a separate layer. Or if I have to just keep doing it manually.

Screen Shot 2019-08-19 at 3.26.02 PM.png

TOPICS
Scripting

Views

2.5K

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

Explorer , Aug 19, 2019 Aug 19, 2019

I've tried the script on only 3 empty TextFrames regardles of stacking order 😞

It was too quick !!

Ofcourse stacking order is very important !!!

In my environment there is ONE page only and ONE source Layer only.

In such conditions script written below works.

var fl = app.activeDocument.layers.firstItem();

var items = fl.pageItems.everyItem().getElements();

var i = items.length;

while ( i-- ) {

    app.activeDocument.layers.add( { name : 'Layer_'+i } )

    items.itemLayer = app.activeDocument.layers.item

...

Votes

Translate

Translate
Explorer ,
Aug 19, 2019 Aug 19, 2019

Copy link to clipboard

Copied

Hello,

try to select all the items on Layer 1

then run this:

var sel = app.selection

var i = sel.length;

while ( i-- ) {

    app.activeDocument.layers.add( { name : 'Layer_'+i } )

    sel.itemLayer = app.activeDocument.layers.itemByName( 'Layer_'+i );

    }

regards

a.

Votes

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
Community Beginner ,
Aug 19, 2019 Aug 19, 2019

Copy link to clipboard

Copied

Hi platm72,

Thanks so much for your response. I am a novice when it comes to scripts. I know where to save script files on my system to then run them but I don't know where to put this code? Can you please tell me where I copy and paste the code to make the script work?

Thank you

Votes

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
Explorer ,
Aug 19, 2019 Aug 19, 2019

Copy link to clipboard

Copied

Sure 🙂

Open ExtendScript Toolkit, then paste the code and save the script – best way in Scripts Folder inside Main Indesign Folder.

The script will run if at least on item on page will be selected.

Write me please if you need some modifications or improvements of this simple script 🙂

regards

a

Votes

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
Community Beginner ,
Aug 19, 2019 Aug 19, 2019

Copy link to clipboard

Copied

Thank you!!!

That worked, howeverand I might be pressing my luck here—is there any way to have it create the layers in the same order as the were originally stacked?

Below is

1. Screen shot of the page before running the script

2. Screen shot after running the script. It successfully created the layers, however out of order so items are burried

3. In case it is helpful, a screen shot of what the layers list looks like after running the script.

Thanks!

Screen Shot 2019-08-19 at 5.46.02 PM.png

Screen Shot 2019-08-19 at 5.45.40 PM.png

Screen Shot 2019-08-19 at 5.47.36 PM.png

Votes

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
Explorer ,
Aug 19, 2019 Aug 19, 2019

Copy link to clipboard

Copied

I've tried the script on only 3 empty TextFrames regardles of stacking order 😞

It was too quick !!

Ofcourse stacking order is very important !!!

In my environment there is ONE page only and ONE source Layer only.

In such conditions script written below works.

var fl = app.activeDocument.layers.firstItem();

var items = fl.pageItems.everyItem().getElements();

var i = items.length;

while ( i-- ) {

    app.activeDocument.layers.add( { name : 'Layer_'+i } )

    items.itemLayer = app.activeDocument.layers.itemByName( 'Layer_'+i );

    }

fl.remove();

Now you don't need to select enything. Just open document witch ONE page and ONE layer and run the script. Stacking order should be saved.

regards

a.

A.pngB.png

C.png

D.png

Votes

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
Community Beginner ,
Aug 20, 2019 Aug 20, 2019

Copy link to clipboard

Copied

This is AMAZING! I cannot thank you enough!! You saved me so much time.

Very much appreciated.

Thanks!

Votes

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
Explorer ,
Oct 14, 2021 Oct 14, 2021

Copy link to clipboard

Copied

Hi.
Does the script work in the latest versions of inDesign 2020 and 2021? I tested both. All new layers are empty. This script would help me a lot. I need help.

Votes

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
Community Expert ,
Oct 14, 2021 Oct 14, 2021

Copy link to clipboard

Copied

Just try it out.

If it will not work report the error message(s) you are seeing.

Do your tests on a duplicate of your document.

 

Regards,
Uwe Laubender

( ACP )

Votes

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
Explorer ,
Oct 14, 2021 Oct 14, 2021

Copy link to clipboard

Copied

I tested, no error message. Code doesn't work in inDesign 2021 (16.1). I'm sending a screen shot.

Regards,

Kamil

Votes

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
Community Expert ,
Oct 15, 2021 Oct 15, 2021

Copy link to clipboard

Copied

LATEST

Ok. That means, basically the script is working, but it does not do what you expected.

Means: it's up to platm72 to see into the issue. Contact platm72, you can send a private message, just click the avatar and work the button "Send Message"…

 

And you can make your document available as well for testing.

 

Regards,
Uwe Laubender

( ACP )

Votes

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
Community Expert ,
Sep 12, 2019 Sep 12, 2019

Copy link to clipboard

Copied

Hi @platm72,

I hope this reply goes through in the new forum.

 

The stacking order of elements has to be seen spread by spread ( InDesign CS5 version 7 and above! ).

And the array that maps this stacking order is spread.allPageItems.

( At least when no multistate objects with two or more states or buttons with two or three states are involved, then it would be more complicated. )

 

So you could build a reliable stacking order looping the allPageItems array of a spread.

But note the following: If you want to move page items where the parent is the spread and not the ones that are anchored or part of a nested structure like groups or within a table's graphic cells or inserted otherwise in graphic frames you have to test for parent.constructor.name == "Spread". All anchored or nested items will move along with the one where the parent is the spread.

 

If you want to free items from their nested status in the right stacking order you have to either unanchor them ( all page items with parent.constructor.name == "Character" or first anchor them to temp text frames on the spread and then release them on the spread ( with all otherwise nested items test for: parent constructor.name != "Spread" && parent constructor.name != "Character" ).

 

Regards,
Uwe

 

FWIW: This my first attempt for a reply on the new forum after its gone "live".

 

Regards,

Uwe

Votes

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