INDD: Export all Items in all Layers

Explorer ,
Feb 10, 2022 Feb 10, 2022

Copy link to clipboard

Copied

Hello there

I was wondering how to acces the items, in an Layer, and export them as Jpegs.

I tried using app.selection[i].itemLayer.getPageItems, but it doesn't work.

This is what my Indesign File looks like:

schlindibus_1-1644480131240.png

 


Also you see there a group, which needs to be exported as one jpg, but im not really sure how to achieve that.

Does anyone know?

THANKS A LOT!

TOPICS
Scripting

Views

138

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 2 Correct answers

Explorer , Feb 10, 2022 Feb 10, 2022
Hello @Laubender Yes that would have been a possible way. But defining things in Code isn't the goal.I came up with this Version which works perfectly fine:var allLayers = doc.layers; if (allLayers.length > 0) { for (var i = 0; allLayers.length > i; i++) { var allElements = allLayers[i].pageItems; var layerName = allLayers[i].name; if (layerName.indexOf("Immo") || layerName.indexOf("Stellen")) { if (allElements.length > 0) { for (var j = 0;...

Likes

Translate

Translate
Explorer , Feb 10, 2022 Feb 10, 2022
My Script also checks if the "Ebene 1" in the Screenshot contains Immo or Stellen. If thats true, then the Images get exportet. All other files which don't have a Layer which contains Immo or Stellen, the Items won't get exported as a Jpg :).

Likes

Translate

Translate
Explorer ,
Feb 10, 2022 Feb 10, 2022

Copy link to clipboard

Copied

This is what I came up with, but doesn't work:

var allLayers = doc.layers;		
   if (allLayers.length > 0) {			
      for (var i = 0; allLayers.length > i; i++)
         {
           var allElements = allLayers[i].getPageItems;
             if(allElements.length > 0 ) {
                for (var j = 0; allElements.length > j; j++) {
                  var element = allElements[i];
                  var elementName = element.name;
                  var path = imageFolder + "/" + elementName + ".jpg";
                  var savedFile = new File(path);
                  element.exportFile(ExportFormat.jpg, savedFile);
                }
             }				
         }
     }

I'm not sure why but I'm getting an error that allLayers[i].getPageItems :

schlindibus_0-1644483447565.png

Has anyone a different approch to this?

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
Adobe Community Professional ,
Feb 10, 2022 Feb 10, 2022

Copy link to clipboard

Copied

As you have discovered, "getPageItens" is not a method for any DOM object, including the Layer object. 

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
Adobe Community Professional ,
Feb 10, 2022 Feb 10, 2022

Copy link to clipboard

Copied

Turn off the visibilty of all other objects and then export this Page to JPG, or for better Quality export as PDF/X-4, open that in Photoshop and save as JPG.

 

But t why JPG? With text and graphic it is not a good idea anyway.

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 ,
Feb 10, 2022 Feb 10, 2022

Copy link to clipboard

Copied

Ih I was to hide the other content, the whole Page would be exportet, which isn't the Goal. The goal is to export each Item in the Layer with the size it is.

Exporting as an jpg because I need to have the pdf's and the Graphics as an jpg. To import it after to PS  is not the goal. 

But right now I'm a little bit clueless how to make this.

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
Adobe Community Professional ,
Feb 10, 2022 Feb 10, 2022

Copy link to clipboard

Copied

Hi schlindibus,

you could loop this array:

var pageItemsArray = doc.layers.itemByName("Ebene 1").pageItems.everyItem().getElements();

 

Note: Layers have document scope. So you collect items on pages and pasteboards.

You do not collect items on parent pages ("Musterseiten").

 

The array above contains an array of first level page items.

Nested items, like items in groups, are not explicitely stored.

 

The Layers panel has spread scope.

It only shows all the items of a single spread.

 

Regards,
Uwe Laubender

( ACP )

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 ,
Feb 10, 2022 Feb 10, 2022

Copy link to clipboard

Copied

Hello @Laubender 

Yes that would have been a possible way. But defining things in Code isn't the goal.

I came up with this Version which works perfectly fine:

var allLayers = doc.layers;
    if (allLayers.length > 0) {
      for (var i = 0; allLayers.length > i; i++) {
        var allElements = allLayers[i].pageItems;
        var layerName = allLayers[i].name;
        if (layerName.indexOf("Immo") || layerName.indexOf("Stellen")) {
          if (allElements.length > 0) {
            for (var j = 0; allElements.length > j; j++) {
              var element = allElements[j];
              var elementName = element.name;
              var path = imageFolder + "/" + elementName + ".jpg";
              var savedFile = new File(path);
              element.exportFile(ExportFormat.jpg, savedFile);
            }
          }
        }
      }
      doc.close(SaveOptions.NO);
    }

Thanks for your replies!

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 ,
Feb 10, 2022 Feb 10, 2022

Copy link to clipboard

Copied

My Script also checks if the "Ebene 1" in the Screenshot contains Immo or Stellen. If thats true, then the Images get exportet. All other files which don't have a Layer which contains Immo or Stellen, the Items won't get exported as a Jpg :).

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
Adobe Community Professional ,
Feb 10, 2022 Feb 10, 2022

Copy link to clipboard

Copied

Hi schlindibus,

also see into app.jpegExportPreferences to define the details of the JPEG export. See DOM description at:

https://www.indesignjs.de/extendscriptAPI/indesign-latest/#JPEGExportPreference.html#d1e415512

 

Regards,
Uwe Laubender

( ACP )

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
Adobe Community Professional ,
Feb 10, 2022 Feb 10, 2022

Copy link to clipboard

Copied

LATEST

Hi @schlindibus Here are the methods and properties for the Layer object:

 

https://www.indesignjs.de/extendscriptAPI/indesign-latest/#Layer.html#d1e199876

 

There is also .allPageItems, which gets groups and pageitems within groups.

 

Here .allPageItems returns 5 items, and .pageItems returns 2 items:

 

Screen Shot 24.png

 

var l = app.documents[0].activeLayer
var api = l.allPageItems
var pi = l.pageItems

$.writeln("All Page Items: " + api.length)
//returns 5 items

$.writeln("Page Items: " + pi.length)
//returns 2 items

 

 

 

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