Copy link to clipboard
Copied
Hi, I want to create a script that will prevent a user from exporting any pdf when unwanted Layers are present. eg: Layer1, Layer Copy
Try this below snippet:
#target indesign
#targetengine "session"
main();
function main(){
var myBeforeExportEvList = app.addEventListener("beforeExport", checkLayer, false);
}
function checkLayer(e){
// Here this is your list of layer names to be matched === If matches code will stop export of pdf
var listOfLayerNames = ["Layer", "Layer Copy", "Test Layer"];
var match = false;
for(var i = 0; i < app.activeDocument.layers.length; i++){
for(var j = 0; j < listOfLaye
...
Just one more validation added. Now you check & see:
#target indesign
#targetengine "session"
main();
function main(){
var myBeforeExportEvList = app.addEventListener("beforeExport", checkLayer, false);
}
function checkLayer(e){
var listOfLayerNames = ["N-Spacing", "Specification Box", "Dieline", "FPO/Variable Area", "ARTWORK", "Pre-Printed Artwork", "Substrate - for foil/clear plastic", "Technical Details"];
var match = "";
var outOfList = "";
for(var i = 0; i < app.acti
...
Copy link to clipboard
Copied
You just want to match names of layer to some specific texts & if it matches you want to stop them from exporting?
Sunil
Copy link to clipboard
Copied
Well, is it possible that if a layer doesnt match to a list of my specific layers, then it will stop me from exporting.
Copy link to clipboard
Copied
You need to add event listner.
So that it should be invoked before exporting PDF & that script should check layer names & if your requirement doesn't fullfills it should prevent the default action.
Sunil
Copy link to clipboard
Copied
Thank you, do you have any samples of that script? Im still a newb
Copy link to clipboard
Copied
Copy link to clipboard
Copied
This is the script Ive done so far, unfortunately, it displays all the present Layers on the document.
Copy link to clipboard
Copied
Try this below snippet:
#target indesign
#targetengine "session"
main();
function main(){
var myBeforeExportEvList = app.addEventListener("beforeExport", checkLayer, false);
}
function checkLayer(e){
// Here this is your list of layer names to be matched === If matches code will stop export of pdf
var listOfLayerNames = ["Layer", "Layer Copy", "Test Layer"];
var match = false;
for(var i = 0; i < app.activeDocument.layers.length; i++){
for(var j = 0; j < listOfLayerNames.length; j++){
if(listOfLayerNames[j] == app.activeDocument.layers[i].name){
match = true;
break;
}
}
if(match) break;
}
if(match){
e.stopPropagation();
e.preventDefault();
}
}
Best
Sunil
Copy link to clipboard
Copied
This is perfect! thank you so much. How can I create an alert showing all the unwanted layers?
Copy link to clipboard
Copied
Plus, how can I activate the script without actually clicking it? Thanks in advance
Copy link to clipboard
Copied
I modified the script youve sent,"if it matches the list of layers" then it will continue exporting. The only thing I need now is it will display all the unwanted layers that doesnt matched the list and the script will automatically run without manually activating it.
Copy link to clipboard
Copied
You can put this script in start up folder instead of script panel. So every time your application restarts this script will be executed.
Best
Sunil
Copy link to clipboard
Copied
Try this code sample :
#target indesign
#targetengine "session"
main();
function main(){
var myBeforeExportEvList = app.addEventListener("beforeExport", checkLayer, false);
}
function checkLayer(e){
// Here this is your list of layer names to be matched === If matches code will stop export of pdf
var listOfLayerNames = ["N-Spacing", "Specification Box", "Dieline", "FPO/Variable Area", "ARTWORK", "Pre-Printed Artwork", "Substrate - for foil/clear plastic", "Technical Details"];
var match = "";
for(var i = 0; i < app.activeDocument.layers.length; i++){
for(var j = 0; j < listOfLayerNames.length; j++){
if(listOfLayerNames[j] == app.activeDocument.layers[i].name){
match += app.activeDocument.layers[i].name+"\n";
}
}
}
if(match != ""){
if (!confirm("Unwanted Layers is present:"+"\r"+match)){
e.stopPropagation();
e.preventDefault();
}
}
}
Best
Sunil
Copy link to clipboard
Copied
Hi @Sunil Yadav I tried the code youve sent, It shows the matched layers(listOfLayerNames) on the dialog box. Is there a way that it will show whats not on the list? Thank you so much
Copy link to clipboard
Copied
Sure,
Try this snippet :
#target indesign
#targetengine "session"
main();
function main(){
var myBeforeExportEvList = app.addEventListener("beforeExport", checkLayer, false);
}
function checkLayer(e){
var listOfLayerNames = ["N-Spacing", "Specification Box", "Dieline", "FPO/Variable Area", "ARTWORK", "Pre-Printed Artwork", "Substrate - for foil/clear plastic", "Technical Details"];
var match = "";
var outOfList = "";
for(var i = 0; i < app.activeDocument.layers.length; i++){
for(var j = 0; j < listOfLayerNames.length; j++){
if(listOfLayerNames[j] == app.activeDocument.layers[i].name) match += app.activeDocument.layers[i].name+"\n";
else outOfList += app.activeDocument.layers[i].name+"\n";
}
}
if(match != ""){
if (!confirm("Unwanted Layers is present:"+"\r"+outOfList)){
e.stopPropagation();
e.preventDefault();
}
}
}
Best
Sunil
Copy link to clipboard
Copied
Hello @Sunil Yadav im having this error. The higlighted layers are those whose not on the list, but when I scrolled down the dialg box, it still shows all the layer names
Copy link to clipboard
Copied
Just one more validation added. Now you check & see:
#target indesign
#targetengine "session"
main();
function main(){
var myBeforeExportEvList = app.addEventListener("beforeExport", checkLayer, false);
}
function checkLayer(e){
var listOfLayerNames = ["N-Spacing", "Specification Box", "Dieline", "FPO/Variable Area", "ARTWORK", "Pre-Printed Artwork", "Substrate - for foil/clear plastic", "Technical Details"];
var match = "";
var outOfList = "";
for(var i = 0; i < app.activeDocument.layers.length; i++){
var found = false;
for(var j = 0; j < listOfLayerNames.length; j++){
if(listOfLayerNames[j] == app.activeDocument.layers[i].name){
match += app.activeDocument.layers[i].name+"\n";
found = true;
break;
}
}
if(!found) outOfList += app.activeDocument.layers[i].name+"\n";
}
if(match != ""){
if (!confirm("Unwanted Layers is present:"+"\r"+outOfList)){
e.stopPropagation();
e.preventDefault();
}
}
}
Best
Sunil
Copy link to clipboard
Copied
This is perfect! thank you so much!