Copy link to clipboard
Copied
Hello,
I've been trying to use a jsx script to rasterize a specific layer called Artwork. This is my script below. Everytime I try to trigger the script, it crashes Illustrator. I've narrowed it down to the last line of code that seems to be crashing it, but that is the only line of code I can see in the scripting doc that will do what I need it to.
I'm using Illustrator 2022 but I've also tried it on 2023 and that also doesn't work. I don't suppose this is a glitch is it or is my script wrong?
Thanks very much.
var doc = app.activeDocument;
var sourceArt = doc.layers.getByName("Artwork");
var clipBounds = undefined;
// Rasterization options
var options = new RasterizeOptions();
options.resolution = 300;
options.antiAliasingMethod.TYPEOPTIMIZED;
options.transparency = true;
options.convertSpotColors = false;
options.includeLayers = true;
// Rasterize layers with options
doc.rasterize(sourceArt, clipBounds, options);
1 Correct answer
I presume "sourceArt" should be a vector item, not a layer.
Explore related tutorials & articles
Copy link to clipboard
Copied
I presume "sourceArt" should be a vector item, not a layer.
Copy link to clipboard
Copied
Yes @femkeblanco is right. Document.rasterize crashes if you give it a Layer or even PageItems objects.
This works:
var sourceArt = doc.layers.getByName("Artwork").pageItems[0];
- Mark
Copy link to clipboard
Copied
Thanks very both of you, that worked. Really appreciate your help!
Do you know if there is a simple way to rasterize everything within that layer? I've grouped it and that seems to do the trick, but just wondering if I can target the full layer without grouping.
Copy link to clipboard
Copied
I can't think of a simpler way than moving objects into group (temporarily). There is another approach, which is probably *less* simple which is to script a whole artboard export. Or a quick, png version is Document.imageCapture:.
var doc = app.activeDocument,
bounds = doc.artboards[0].artboardRect,
f = File(Folder.desktop + '/test.png'),
options = new ImageCaptureOptions();
options.antiAliasing = true;
options.resolution = 500;
options.transparency = false;
doc.imageCapture(f, bounds, options);
Then you would have to place/embed the exported image depending on what you wanted.
But, no, I think the grouping method would be simplest.
- Mark

