Copy link to clipboard
Copied
Hi! I am looking to automate a step for a process I'm working on.
I have a file with multiple overlapping layers arranged in a certain way for printing purposes for card designs over several pages. I've also utilised Variable Data to feed data into the file which changes depending on the data. I proceed to turn on and off visibility of only certain layers before printing. It's a repetitive process as the visibility of the specific layers to be turned off and on are fixed.
Am wondering if there is a way to automate the turning off and on of specific layers and save each desired layout on screen as PDF? Each of the end layout is fixed so the steps are specific.
thanks!
1 Correct answer
Is it very much possible, i have written a small snippet to do this have a look. At the top, I have defined two variables
- layertoHide :- this is an array with names of the layers that need to be turned off, all the remaining layers are made visible
- destinationFilePath :- This is the path of the folder where you want to export the pdf, notice the path ends with a trailing /
- The output file name of the pdf is the name of all the layers to be hidden concatenated with a ,
var layertoHide = ["Layer
...
Explore related tutorials & articles
Copy link to clipboard
Copied
You can easily toggle visibility of specific layers by scripting, if you can specifically target those layers. Presuming they are named, the easiest way would be to target their name or part of their name. For example, the snippet below will make all layers starting with the (capital) letter X invisible.
for (var i = 0; i < app.activeDocument.layers.length; i++) {
var prefix = app.activeDocument.layers[i].name.substr(0, 1);
if (prefix == "X") {
app.activeDocument.layers[i].visible = false;
}
}
Copy link to clipboard
Copied
I don't know how your documents are structured, but using Layer Visibility variables (see Variables palette) in conjunction with batch processing (see Actions palette) may be an appropriate approach.
Copy link to clipboard
Copied
Is it very much possible, i have written a small snippet to do this have a look. At the top, I have defined two variables
- layertoHide :- this is an array with names of the layers that need to be turned off, all the remaining layers are made visible
- destinationFilePath :- This is the path of the folder where you want to export the pdf, notice the path ends with a trailing /
- The output file name of the pdf is the name of all the layers to be hidden concatenated with a ,
var layertoHide = ["Layer1", "Layer 2", "Layer 4"]
var destinationFilePath = "/Users/manan/Downloads/"
for(var i = 0; i < app.activeDocument.layers.length; i++)
{
var l = app.activeDocument.layers[i]
l.visible = true
for(var j = 0; j < layertoHide.length; j++)
{
try{
var ly = layertoHide[j]
if(ly == l.name)
{
l.visible = false
layertoHide = layertoHide.slice(0, i).concat(layertoHide.slice(i + 1))
break;
}
}catch(e){}
}
}
var pdfSaveOptions = new PDFSaveOptions();
pdfSaveOptions.pDFPreset = "[High Quality Print]"
pdfSaveOptions.viewAfterSaving = false;
app.activeDocument.saveAs(new File(destinationFilePath + layertoHide.toString() + ".pdf"), pdfSaveOptions)
-Manan

