Last active
July 23, 2021 15:19
-
-
Save asfdfdfd/346effc4c05aa8343b37 to your computer and use it in GitHub Desktop.
Adobe Illustrator CS6 script that rasterizes every GroupItem from the first layer of active document to the separate png file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function captureImage(fileName, document, clipRect) { | |
var fileOutput = new File("/tmp/exportpng/" + fileName); | |
var imageCaptureOptions = new ImageCaptureOptions(); | |
imageCaptureOptions.resolution = 300; | |
imageCaptureOptions.transparency = true; | |
document.imageCapture(fileOutput, clipRect, imageCaptureOptions); | |
} | |
var docSource = app.activeDocument; | |
$.writeln("Document width: " + docSource.width + ", height: " + docSource.height); | |
var layer = docSource.activeLayer; | |
// Rasterize only first 3 items for debug purposes. Remove for release usage. | |
var groupItemsLength = layer.groupItems.length > 3 ? 3 : layer.groupItems.length; | |
for (var i = 0; i < groupItemsLength; i++) { | |
var groupItem = layer.groupItems[i]; | |
var docTemp = app.documents.add(DocumentColorSpace.CMYK, app.activeDocument.width, app.activeDocument.height); | |
var layerTemp = docTemp.layers[0]; | |
var groupItemTemp = groupItem.duplicate(layerTemp, ElementPlacement.PLACEATEND); | |
var groupItemBounds = groupItemTemp.visibleBounds; | |
var groupItemLeft = groupItemBounds[0]; | |
var groupItemTop = groupItemBounds[1]; | |
var groupItemWidth = groupItemBounds[2] - groupItemBounds[0]; | |
var groupItemHeight = groupItemBounds[1] - groupItemBounds[3]; | |
captureImage(i + ".png", docTemp, groupItemTemp.visibleBounds); | |
$.writeln("left: " + groupItemLeft + ", top: " + groupItemTop + ", width: " + groupItemWidth + ", height: " + groupItemHeight); | |
docTemp.close(SaveOptions.DONOTSAVECHANGES); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment