Skip to main content
Inspiring
January 31, 2024
Answered

document.rasterize() crashing illustrator

  • January 31, 2024
  • 2 replies
  • 615 views

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);

This topic has been closed for replies.
Correct answer femkeblanco

I presume "sourceArt" should be a vector item, not a layer. 

2 replies

m1b
Community Expert
Community Expert
January 31, 2024

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 

Inspiring
February 1, 2024

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.

m1b
Community Expert
Community Expert
February 1, 2024

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

femkeblanco
femkeblancoCorrect answer
Legend
January 31, 2024

I presume "sourceArt" should be a vector item, not a layer.