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

Pages to Layers Script

New Here ,
Sep 21, 2018 Sep 21, 2018

Copy link to clipboard

Copied

Hello,

Background: The job I'm working on was created using datamerge. Its a postcard that has a common master page background. I merged in an address and map.

As expected I now have over 200 pages of postcards with the merged background, address, and map. I need to export them into separate files that have individual names. So what I would like to do is somehow move the pages into layers on a single page and name the layers the file names I need, then export them using the script, "PageExporterUtility". For those not familiar PageExporter lets you choose a base layer and variable data layers on top and creates and individual file for each using the name of that layer.

The problem I'm running into is that I can't find a way to move all of the pages into layers on one page.  I found was able to make each page it's own layer but it stays on that page. Here's my script so far below.

Thanks for your help.

Jeff

for(var p=0; p<document.pages.length; p++) 

    var myPageItems = document.pages

.pageItems.everyItem().getElements(); 

    var myLayerPage = (p+1); 

    for(var i=0;i<myPageItems.length;i++) 

    { 

        try{var myLayer = app.activeDocument.layers.add ({name: "Page " + myLayerPage});}catch(e){}         

        myPageItems.itemLayer = "Page " + myLayerPage; 

    } 

}

TOPICS
Scripting

Views

1.4K

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

Participant , Sep 21, 2018 Sep 21, 2018

Hi ixladxi,

You were very close... I used your script above and edited as such, notice the last part (added var doc for my script execution purposes):

var doc = app.activeDocument;

for(var p=0; p<document.pages.length; p++)  {

    var myPageItems = document.pages

.pageItems.everyItem().getElements();

    var myLayerPage = (p+1);

    for(var i=0; i < myPageItems.length; i++) {

        try {

            var myLayer = app.activeDocument.layers.add ({name: "Page " + myLayerPage});          

        } cat

...

Votes

Translate

Translate
New Here ,
Sep 21, 2018 Sep 21, 2018

Copy link to clipboard

Copied

I guess I should mention that this is for 2018 CC.

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
Participant ,
Sep 21, 2018 Sep 21, 2018

Copy link to clipboard

Copied

Hi ixladxi,

You were very close... I used your script above and edited as such, notice the last part (added var doc for my script execution purposes):

var doc = app.activeDocument;

for(var p=0; p<document.pages.length; p++)  {

    var myPageItems = document.pages

.pageItems.everyItem().getElements();

    var myLayerPage = (p+1);

    for(var i=0; i < myPageItems.length; i++) {

        try {

            var myLayer = app.activeDocument.layers.add ({name: "Page " + myLayerPage});          

        } catch(e) {}        

        myPageItems.itemLayer = "Page " + myLayerPage;

    }

}

var myPage = doc.pages.add();

for(var x = 0; x < doc.layers.length; x++) {

    doc.layers.pageItems.everyItem().duplicate(myPage);

}

It will add a page at the end of the document and duplicate all the created layers to it.

Hope that helps.

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
New Here ,
Sep 21, 2018 Sep 21, 2018

Copy link to clipboard

Copied

Thank you so much! This worked. It combines it all on the last page.

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 ,
Oct 01, 2018 Oct 01, 2018

Copy link to clipboard

Copied

Benreyn This works very well! I have some before and after steps that I would like to add in order to automate a portion of my workflow. I'm more familiar with AppleScript than .jsx and believe I will need to jump from Excel to BBedit to InDesign to accomplish what I'm envisioning.

My process will be extracting 2 columns of tabbed data, cleaning spaces & line endings, InDesign Data Merge, this script, and moving the resulting layers to the working document.

I want to take a shot at doing it myself but would greatly appreciate your thoughts and or warnings if any.

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

Copy link to clipboard

Copied

LATEST

If you still had access to the original un-merged INDD file, would my Data Merge to Unique Names script be of use? Here's a video of it in action: Episode 1: Data Merge to Unique Names - InDesign Javascript by Colecandoo - YouTube

If the answer wasn't in my post, perhaps it might be on my blog at colecandoo!

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