Copy link to clipboard
Copied
I tried app.activeDocument.selection[0].exportFile(ExportFormat.PNG, File("~/Desktop/temp/1.png"), false);
but it says exportFile is not a function in ExtendedScript.
if you're using the latest CC version, use this line
app.activeDocument.exportSelectionAsPNG(File("c:/temp/selection.png"));
Copy link to clipboard
Copied
function exportFile is only for activeDocument, and yet - swap the format and path
// app.activeDocument.exportFile(exportFile, exportFormat [, options])
app.activeDocument.exportFile(File("~/Desktop/temp/1.png"), ExportFormat.PNG);
Copy link to clipboard
Copied
I tried this and it exports entire artboard, including all the objects. How do we export only selected object instead?
Copy link to clipboard
Copied
if you're using the latest CC version, use this line
app.activeDocument.exportSelectionAsPNG(File("c:/temp/selection.png"));
Copy link to clipboard
Copied
Yes~ it's really a clean way to do it. Thanks 😃
Copy link to clipboard
Copied
I do export at so:
if (selection.length) {
// png options
var ex = new ExportOptionsPNG24(),
exType = ExportType.PNG24,
file = new File("~/Desktop/1.png"),
isReplaceFile = false;
ex.artBoardClipping = true;
if (file.exists) {
isReplaceFile = confirm('Replace file - "' + file.toString().replace(file.path, '').slice(1) + '"');
}
else {
isReplaceFile = true;
}
if (isReplaceFile) {
// run fit artboard to selection
activeDocument.artboards[activeDocument.artboards.getActiveArtboardIndex()].artboardRect = selection[0].visibleBounds;
// export
app.activeDocument.exportFile(file, exType, ex);
// reset - fit artboard to selection
app.undo();
}
}
else {
alert('Please select an object');
}