Skip to main content
Participant
September 21, 2018
Répondu

Pages to Layers Script

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; 

    } 

}

Ce sujet a été fermé aux réponses.
Meilleure réponse par Benreyn

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.

3 commentaires

Colin Flashman
Community Expert
Community Expert
October 14, 2018

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!
Benreyn
BenreynRéponse
Participating Frequently
September 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});          

        } 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.

ixladxiAuteur
Participant
September 21, 2018

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

ixladxiAuteur
Participant
September 21, 2018

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