Yes you can export a selection. Selection is an array, so if the selection is more than one object you would have to handle how to group the pageitems. It could get complicated if the page items are on different layers. By default a page item’s name returns as nothing unless it has been named in the Layers panel, but the name could also be scripted. Something like this, which exports to the desktop:
app.jpegExportPreferences.properties = {
antiAlias: true,
embedColorProfile: true,
exportResolution: 72,
jpegColorSpace: JpegColorSpaceEnum.RGB,
jpegQuality: JPEGOptionsQuality.maximum,
simulateOverprint: false,
}
var sel = app.documents[0].selection[0];
var lay = sel.itemLayer;
var pin = sel.name;
//sel.name returns as "" by default
if (sel.name == "") {
pin = "mySelection"
}
//the jpg name for export—the selection’s Layer - the selection’s name + .jpg
var fn = "/" + lay.name + "-" + pin +".jpg"
$.writeln(sel.name)
sel.exportFile(ExportFormat.jpg, File(Folder.desktop + fn));
@rob day
You're the man! With a few changes and your Script, it works!
For everyone wondering how to do it, this is my take, bases on @rob day 's soulution:
app.jpegExportPreferences.properties = {
antiAlias: true,
embedColorProfile: true,
exportResolution: 300,
jpegColorSpace: JpegColorSpaceEnum.RGB,
jpegQuality: JPEGOptionsQuality.maximum,
simulateOverprint: false,
}
var myFolder = Folder.selectDialog ("Select location to export the Jpeg files.");
if (myFolder != null) {
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));
}
} else {
alert("Please select at least one Layer!");
}
}