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

Batch export groups to jpg

Community Beginner ,
Feb 17, 2020 Feb 17, 2020

Copy link to clipboard

Copied

Im looking to create a script that scans an indesign document and exports specific images and grouped items to a location. Im still new to scripting and ExtendScript, but I kinda have a handle on JS so it seems to be making sense... so far. I've used the following code from two other posts on here to get me started with what I needed, but there seems to be a few hiccups preventing this from working.

So far I can export all of the images to a desktop location, however, the grouped items are throwing an error. It is stating the grpFile.exportFile is not a function. I haven't even gotten to the specific selection, or ommission of certain images or groups. That seems to be phase III or IV


This is the code I am using so far:


var i,
myDoc = app.activeDocument,
myGroups = app.activeDocument.groups,
apis = myDoc.links.everyItem().getElements(), rect, fileName;

alert("Script is running. Press OK and wait until done...");

while ( rect = apis.pop() ) {
rect = rect.parent.parent;
if ( !(rect.hasOwnProperty ("graphics") ) ){
continue;
}
fileName = File ( rect.graphics[0].itemLink.filePath ).name;
fileName = fileName.replace( /\.[a-z]{2,4}$/i, '.jpg' );
app.jpegExportPreferences.exportResolution = 72;
app.jpegExportPreferences.jpegQuality = JPEGOptionsQuality.MEDIUM;

var myFile = new File ("/Users/q1344763/Desktop/export-test/"+ fileName);
rect.exportFile(ExportFormat.JPG, myFile);
}

alert ("Exporting Groups...");

for ( i = 0; i < myGroups.length; i++ ) {
var grpFile = new File( "/Users/q1344763/Desktop/export-test/groups/" + i + '.jpg' );
grpFile.exportFile( ExportFormat.JPG, grpFile, false );
};

alert ("Done.");

TOPICS
Scripting

Views

1.6K

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

Community Expert , Feb 18, 2020 Feb 18, 2020

You want to call exportFile on myGroups[i], not grpFile.

 

Also, does the "groups" folder exist before you try the export? If not, that could be throwing it. 

 

var fol = Folder("/Users/q1344763/Desktop/export-test/groups/");

if (!fol.exists) {

   fol.create();

}

Votes

Translate

Translate
Community Expert , Aug 03, 2020 Aug 03, 2020

Here is the full script that Phlume originally wrote with my corrections. If it fails, please post the error message here. 

 

 

 

 

var i,
myDoc = app.activeDocument,
myGroups = app.activeDocument.groups,
apis = myDoc.links.everyItem().getElements(), rect, fileName;

alert("Script is running. Press OK and wait until done...");

while ( rect = apis.pop() ) {
rect = rect.parent.parent;
if ( !(rect.hasOwnProperty ("graphics") ) ){
continue;
}
fileName = File ( rect.graphics[0].itemLink.filePath ).n
...

Votes

Translate

Translate
Community Expert , Aug 03, 2020 Aug 03, 2020

Hi aviel222,

my suggested code would be the following:

 

var exportPrefs = app.jpegExportPreferences.properties;

var newExportPrefs = 
{
	antiAlias : true ,
	exportResolution : 600 ,
	jpegColorSpace : JpegColorSpaceEnum.CMYK ,
	jpegQuality : JPEGOptionsQuality.MAXIMUM ,
	jpegRenderingStyle : JPEGOptionsFormat.BASELINE_ENCODING ,
	simulateOverprint : true
};

app.jpegExportPreferences.properties = newExportPrefs ;

var doc =app.documents[0];
var exportFolder = doc.fullName.parent;
var allGroupsA
...

Votes

Translate

Translate
Explorer ,
Aug 04, 2020 Aug 04, 2020

Copy link to clipboard

Copied

I understood what you were saying
But I have no idea what to look for and also I will find something I will not know how to integrate in the code.
I will open a new topic in the forum, with an exact explanation of what the goal is.

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
Explorer ,
Aug 04, 2020 Aug 04, 2020

Copy link to clipboard

Copied

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 Expert ,
Aug 04, 2020 Aug 04, 2020

Copy link to clipboard

Copied

LATEST

aviel222 asked me elsewhere to restrict the code of my script to the groups of the document's active layer.

Well, we could restrict the array of groups we loop through to the ones of the active layer.

 

Instead of writing:

var allGroupsArray = doc.groups.everyItem().getElements();

 

we could write:

var allGroupsArray = doc.activeLayer.groups.everyItem().getElements();

 

Regards,
Uwe Laubender

( ACP )

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