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.");
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();
}
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
...
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
...
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.
Copy link to clipboard
Copied
Copy link to clipboard
Copied
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 )