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

Export mutations with several different layers

Community Beginner ,
Jan 27, 2021 Jan 27, 2021

Copy link to clipboard

Copied

Hey dear community!

 

Can you export the same Document (PDF) several times automatically? Because I often have like 10 or 20 Code-Mutations on a payment slip on my Doc and I always have to export them manually one at a time. Would be perfect if I could select the layers that should be exported in succession (with the main layer always exported logically).

 

Does anybody know about a Script or a function in Indesign which can do that? Couldn't google anything about it 😕

 

Cheers and thanks, Sebastian

 

export-layers.png



[ attachment inserted as inline image by moderator ]

TOPICS
How to , Import and export , Print , Scripting

Views

374

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

Advisor , Jan 27, 2021 Jan 27, 2021

Hi sebastianp39925710,

 

Give the below code a try for your needs.

 

var doc = app.activeDocument;
var myFolder = doc.filePath;

export_preset = app.pdfExportPresets.itemByName("[High Quality Print]");

if (!(export_preset.isValid)){ 
    alert('The PDF export preset does not exist.'); 
    exit(); 
   }

function myGetVisibleLayers(){
 var myVisibleLayers = new Array;
  for (var i = 0; i < doc.layers.length; i++){
   if (doc.layers[i].visible == true) {   
    myVisibleLayers.push(doc.layers[i].ind
...

Votes

Translate

Translate
Community Expert ,
Jan 27, 2021 Jan 27, 2021

Copy link to clipboard

Copied

Hi,

can you confirm the exact version of your software and operating system?

Have you considered creating a data merge approach instead of layers?

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
Advisor ,
Jan 27, 2021 Jan 27, 2021

Copy link to clipboard

Copied

Hi sebastianp39925710,

 

Give the below code a try for your needs.

 

var doc = app.activeDocument;
var myFolder = doc.filePath;

export_preset = app.pdfExportPresets.itemByName("[High Quality Print]");

if (!(export_preset.isValid)){ 
    alert('The PDF export preset does not exist.'); 
    exit(); 
   }

function myGetVisibleLayers(){
 var myVisibleLayers = new Array;
  for (var i = 0; i < doc.layers.length; i++){
   if (doc.layers[i].visible == true) {   
    myVisibleLayers.push(doc.layers[i].index);
      }
   }
      return myVisibleLayers;
  }

 //Layers Manager Dialog/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

  var layerNames = [];

   for (var i = 0; i < doc.layers.length; i++) {
   layerNames.push(doc.layers[i].name);
   }
   var myW = new Window ("dialog", "Layers Manager"), 
   layerGroup = myW.add("group");
   layerGroup.alignChildren = "row";
   var columns = myW.add("group"); columns.spacing=20;
   
   layerGroup.add ('statictext', [-55,28,200, 43], "Select Base Layer(s)");
   var base = columns.add ("listbox", [30, 0, 275, 300] , layerNames, {multiselect: true});
   base.revealItem (doc.layers.length -i/1);
   var selectedBase = []; 
   for (var i = 0; i < base.items.length; i++){selectedBase[0] = base.items[i];}
   base.selection = selectedBase; 

   layerGroup.add ('statictext', [365, 28,603,43], "Select Version Layer(s)");   
   var versions = columns.add ("listbox", [30, 0, 275, 300] , layerNames, {multiselect: true});
   versions.revealItem (doc.layers.length -i/1);   
   var selected = []; 
   for (var i = 0; i < versions.items.length-1; i++){selected[i] = versions.items[i];}
   versions.selection = selected;

   var btn = myW.add("group");
   btn.orientation = "row";
   btn.alignment = ["right", "top"];
   var cancelBtn = btn.add ("button", undefined, "Cancel", {name:"Cancel"});
   var okBtn = btn.add ("button", undefined, "OK", {name:"OK"});
   
   var myResult = myW.show()   
   if(myResult == 1){  
   main();  
   }  
   else if (myResult== 2){  
   exit(0);  
   }  
   function main(){ 

///pdf /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

   if (base.selection == null){
  alert ('Error!\nNo base layer was selected for pdf Output. Please try again.') 
  exit();
  }
  else if (versions.selection == null){
  alert ('Error!\nNo version layers(s) were selected for pdf Output. Please try again.')
  exit();
  }
 var lookup = {};
 for (var j in versions.selection) {lookup[versions.selection[j]] = versions.selection[j];}
 for (var i in base.selection) {
 if (typeof lookup[base.selection[i]] != 'undefined'){
 alert('The layer "'+ [base.selection[i]] + '" cannot be both a base and version layer.\nPlease try again.');
 exit ();
 break;
 } 
 }

 var myVisibleLayers = myGetVisibleLayers();
      
  doc.layers.everyItem().visible = false;

  for (var i = 0; i < base.selection.length; i++){
  var myBase = base.selection[i].index;

  doc.layers[myBase].visible =  true; 
  }

  for (var i = 0; i < versions.selection.length; i++){
  var myVersion = versions.selection[i].index;

  var my_layer = doc.layers[myVersion].name;

  doc.layers[myVersion].visible = true;
  
  app.pdfExportPreferences.pageRange = PageRange.ALL_PAGES

  doc.exportFile(ExportFormat.PDF_TYPE, File(myFolder +'/'+ my_layer + ".pdf"), false, export_preset);

  doc.layers[myVersion].visible = false;
}
  doc.layers.everyItem().visible = false;

  for (var i = 0; i < myVisibleLayers.length; i++){  
    var myLayers = myVisibleLayers[i];
    doc.layers[myLayers].visible =  true; 
    }
    alert('Done Exporting the selected Layers to a PDF!');
}

 

 

Regards,

Mike

 

 

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 ,
Jan 27, 2021 Jan 27, 2021

Copy link to clipboard

Copied

Thanks you two for the quick replies!

 

I have CC Pro, Indesign 16.0.1, Windows 10.

 

@Eric DumasThanks for the info, I will look into Data Merge. I'm always happy to learn new ways.

 

@Mike Brothanks for the script - I'll also try that!

 

Cheers for now

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 ,
Jan 27, 2021 Jan 27, 2021

Copy link to clipboard

Copied

Massive thanks to you @Mike Bro  Mike!

 

The script works perfectly and is exactly what I needed!

 

Cheers and thanks again!

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 ,
Jan 28, 2021 Jan 28, 2021

Copy link to clipboard

Copied

LATEST

One last thing - maybe you could consider adding a possibility to stop the export, because then you would have full control. Some exports are very big, and if you see an error, you could stop and start again. (Unfortunately I can't script very well :D)

 

Thanks again for this VERY helpful script Mike!

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