Copy link to clipboard
Copied
Is there some trick to writing a script to change to the object layer options of a PDF placed in an InDesign file? I have no trouble doing it with placed INDD, PSD, or AI files, but placed PDFs do not work.
For example, here's just a simple script to turn off the second layer of a placed graphic, selected in the active INDD document:
1 Correct answer
Hello @Dan Byer,
In the case of a placed layered PDF exported from InDesign, all the layers are nested in one "layer group" that is "graphicLayers[0]"
If you have a single layer you need to reference by name try this..
try { app.selection[0].graphics[0].graphicLayerOptions.graphicLayers[0].graphicLayers.itemByName("Layer 2").currentVisibility = false;
} catch(e) {}
And if you have a multiple layers you need to reference by name try this..
myLayers = ["Layer 2", "Layer 3"]
for(var i = 0; i <myLaye
...
Copy link to clipboard
Copied
Hi @Dan Byer, this script will list to the console any graphic layers of the selected graphic. It will at least tell you if your pdf has layers that Indesign can see. I tested with a pdf saved from Illustrator and it worked fine. Have a look here for more info.
- Mark
function main() {
// list layers of selected graphic
var item = app.activeDocument.selection[0],
layers;
if (item.hasOwnProperty('graphics'))
item = item.graphics[0];
if (item.hasOwnProperty('graphicLayerOptions'))
layers = item.graphicLayerOptions.graphicLayers;
if (layers == undefined) {
alert('Please select a graphic with layers and try again.')
return;
}
for (var i = 0; i < layers.length; i++) {
$.writeln(i + ': ' + layers[i].name + ' (visible = ' + layers[i].currentVisibility + ')');
}
} // end main
app.doScript(main, ScriptLanguage.JAVASCRIPT, undefined, UndoModes.ENTIRE_SCRIPT, 'script');
Copy link to clipboard
Copied
Hello @Dan Byer,
In the case of a placed layered PDF exported from InDesign, all the layers are nested in one "layer group" that is "graphicLayers[0]"
If you have a single layer you need to reference by name try this..
try { app.selection[0].graphics[0].graphicLayerOptions.graphicLayers[0].graphicLayers.itemByName("Layer 2").currentVisibility = false;
} catch(e) {}
And if you have a multiple layers you need to reference by name try this..
myLayers = ["Layer 2", "Layer 3"]
for(var i = 0; i <myLayers.length; i++){
var myLayerOverride = myLayers[i];
try { app.selection[0].graphics[0].graphicLayerOptions.graphicLayers[0].graphicLayers.itemByName(myLayerOverride).currentVisibility = false;
} catch(e) {}
}
Regards,
Mike
Copy link to clipboard
Copied
Thanks Mike, I didn't know that about Indesign pdfs. 🙂
- Mark
Copy link to clipboard
Copied
Yes, that's exactly what I was missing. It's a layer of a layer. Seems so obvious now! Thanks!

