I'm having trouble writing a js script in indesign cs6 to export my formatted images. the code below (found on this website and slightly modified) only opens the document.
ideally the script would loop through all of the formatted/cropped images in my document and export them into a new folder on the desktop, but with the original file names.
any help would be much appreciated:
test();
function test(){
var myDoc = app.open('/Users/StudioA/Desktop/file.indd');
var myGroups = myDoc.groups;
//for each group...
for (var i = 0;i < myGroups.length; i++){
// for each rectangle in the group...
for(var r = 0; r< myGroups[i].rectangles.length; r++){
var myRect = myGroups[i].rectangles[r];
app.jpegExportPreferences.exportResolution = 300;
app.jpegExportPreferences.jpegQuality = JPEGOptionsQuality.MAXIMUM;
//give it a unique name
var myFile = new File('/Users/StudioA/Desktop/Export/' + myRect.name + '.jpg');
myRect.exportFile(ExportFormat.JPG, myFile);
}
}
}
The file name isn't located on the rectangle but on the link related to the placed graphic. This should do what you want given an open document:
Just adding my verbose version of this, which works from the current selection in InDesign and provides console feedback. It renames the images with the prefix "crop_" and saves them to ~/temp