INDD [Script]: Exporting Layers from multiple InDesing Files as jpg

Explorer ,
Dec 20, 2021 Dec 20, 2021

Copy link to clipboard

Copied

Hello Guys

I was wondering about a Script, that in my head is very hard to realize. Now i wonder, whats your take on that.

What I want to create is a Script, which can do following:

- I want to save InDesign Files in a Folder, which a can Select
- I can choose a Folder in which the jpg's get exported
- Now it loops thorugh each InDesign File and exports the Layers to the destination Folder as a jpg named after the Layer name

I'am wodering how much of an expense that would be, or if it even is possible

Looking forward to hear your thoughts on this

schlindibus

TOPICS
Import and export , Scripting

Views

180

Likes

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

Advocate , Dec 21, 2021 Dec 21, 2021

Hello @schlindibus,

 

Give this a try....

 

 

var myFolder = Folder.selectDialog ("Select location to export the Jpeg files.");
if (myFolder != null){ 
}else{
exit();
}

sourceFolder = Folder.selectDialog('Select the folder with Indesign .indd files.');

IDfileList = new Array();
fileType = "*.indd"
IDfileList = sourceFolder.getFiles(fileType);

for (var i = 0; i < IDfileList.length; i++) {
 var myFile = IDfileList[i];

 app.open(myFile);
}
while (app.documents.length > 0) { 

  var doc = app.activeD
...

Likes

Translate

Translate
Advocate ,
Dec 20, 2021 Dec 20, 2021

Copy link to clipboard

Copied

Hello @schlindibus,

 

If you work on a mac give this a try...

Note you'll need to set the jpeg Export Preferences to your desired settings.

 

 

var myFolder = Folder.selectDialog ("Select location to export the Jpeg files.");
if (myFolder != null){ 
}else{
exit();
}

var AS = "tell application \"Finder\"\r set the dfolder to (choose folder with prompt \"Choose a folder.\")\rset f to (every file of entire contents of folder dfolder whose file type is \"IDdD\") as alias list\rend tell";

var IDfileList = app.doScript(AS, ScriptLanguage.applescriptLanguage);

for (var i = 0; i < IDfileList.length; i++) {
 var myFile = IDfileList[i];

 app.open(myFile);
}

while (app.documents.length > 0) { 

  var doc = app.activeDocument;

for(var p = 0; p < doc.pages.length; p++) {
var myPageName = doc.pages[p].name;

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

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

  for (var i = 0; i < doc.layers.length; i++) {

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

  doc.layers[i].visible = true;

// Set JPEG export preferences 
app.jpegExportPreferences.properties = {
    antiAlias: true,
    embedColorProfile: true,
    exportResolution: 150,
    // exportingSpread: true, // Uncomment if spreads
    jpegColorSpace: JpegColorSpaceEnum.rgb,
    jpegExportRange: ExportRangeOrAllPages.exportRange,
    jpegQuality: JPEGOptionsQuality.maximum,
    jpegRenderingStyle: JPEGOptionsFormat.PROGRESSIVE_ENCODING,
    useDocumentBleeds: false,
    simulateOverprint: false,
    pageString: myPageName,
  }

  doc.exportFile(ExportFormat.jpg,File(myFolder + "/" + my_layer + ".jpg"),false);

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

  for (var i = 0; i < myVisibleLayers.length; i++){  
    var myLayers = myVisibleLayers[i];
    doc.layers[myLayers].visible =  true; 
    }
  }
doc.close(SaveOptions.NO);
}
 alert("Done Exporting Layers to Jpeg's!");

 

 

 

Regards,

Mike

Likes

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
Explorer ,
Dec 20, 2021 Dec 20, 2021

Copy link to clipboard

Copied

Good Morning @mikeb41294032 
Your solution looks actually very close to what I'd  need.
Is there a possibility, to do it on Windows, so I can test it? Also if you exprt the Visible Layers, theyre height is as big as the whole Page right? The goal is, to export them  in Original size of the picture.
Thanks you so much for you0re help, maybe you know if it's even possible to do on Windows machines.

 

Schlindibus

Likes

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
Explorer ,
Dec 21, 2021 Dec 21, 2021

Copy link to clipboard

Copied

Hello Again @mikeb41294032 

Your solution is actually almost what I need. Let's ignore the fact with opening the Files from a Folder, and let's concentrate on the Export. 
When I export the Layers with your Script they look liket this: 

schlindibus_1-1640085602593.jpeg

 

But im trying to get it looking like this: 

schlindibus_2-1640085659469.png

 

so just the items in a layer as one image, without the whole document in the image. Is this even possible? Also I cannot use the select function., because the goal is to export these images fully automated.

I've tried a lot of different stuff but can not figure out how to do it. 

 

Is it even possible?

 

GReetings 

Schlindibus

 

 

 

Likes

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
Advocate ,
Dec 21, 2021 Dec 21, 2021

Copy link to clipboard

Copied

Hello @schlindibus,

 

Give this a try....

 

 

var myFolder = Folder.selectDialog ("Select location to export the Jpeg files.");
if (myFolder != null){ 
}else{
exit();
}

sourceFolder = Folder.selectDialog('Select the folder with Indesign .indd files.');

IDfileList = new Array();
fileType = "*.indd"
IDfileList = sourceFolder.getFiles(fileType);

for (var i = 0; i < IDfileList.length; i++) {
 var myFile = IDfileList[i];

 app.open(myFile);
}
while (app.documents.length > 0) { 

  var doc = app.activeDocument;

  doc.layers.everyItem().locked = false;
  doc.pages.everyItem().pageItems.everyItem().locked = false;

  for(var p = 0; p < doc.pages.length; p++) {
   for (var i = 0; i < doc.layers.length; i++){
    doc.activeLayer = doc.layers[i];
    var myItems = doc.activeLayer.allPageItems;
     try{ doc.pages[p].groups.add (doc.activeLayer.pageItems);}catch(e){}
    }
  }

  app.jpegExportPreferences.properties = {
    antiAlias: true,
    embedColorProfile: true,
    exportResolution: 300,
    jpegColorSpace: JpegColorSpaceEnum.RGB,
    jpegQuality: JPEGOptionsQuality.maximum,
    simulateOverprint: false,
  }

    app.select(SelectAll.ALL);

      var mySelection = app.selection;
      if (mySelection.length > 0) {
          for (var i = 0; i < mySelection.length; i ++) {
              var exportedSelected = mySelection[i];
              var selectedLayer = exportedSelected.itemLayer;				
              var layerName = "/" + selectedLayer.name + ".jpg";
              exportedSelected.exportFile(ExportFormat.jpg, File(myFolder + layerName));		
          }	
          doc.close(SaveOptions.NO);
      } 
  }
     alert("Done Exporting Layers to Jpeg's!");	

 

 

Regards,

Mike

Likes

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
Explorer ,
Dec 22, 2021 Dec 22, 2021

Copy link to clipboard

Copied

LATEST

@mikeb41294032 this is GREAT! Thank you so much!

Can I ask  where you find this things? I haven't found a good Documentation, can you send me a link, if therse a Documentation you are using.

Likes

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