Copy link to clipboard
Copied
I want to create a script that rasterizes selected elements to a single image according to defined parameters. I am interested in CMYK, 200ppi, background: white, preserve spot colors.
Can I somehow use app.executeMenuCommand("Rasterize 8 menu item") for this?
I tried to find something on the subject but failed. Does anyone have a hint?
I have it so far, but I'm stuck on the pop-up š
// select all
app.executeMenuCommand("selectall");
// rasterize
app.executeMenuCommand("Rasterize 8 menu item")
check this thread for a how to rasterize an object sample
https://community.adobe.com/t5/illustrator-discussions/raster-resolution/m-p/9747492#M88839
and this document for all options you need that are missing from the script
https://ai-scripting.docsforadobe.dev/jsobjref/RasterizeOptions.html
let us know if you get stuck and need more help
Hello @irek289170064v73
Give this a try...
raster = function() {
app.executeMenuCommand("selectall");
app.executeMenuCommand("group");
this.doc = app.activeDocument;
this.options = new RasterizeOptions();
this.options.resolution = 200;
this.options.transparency = true;
this.options.antiAliasingMethod = AntiAliasingMethod.ARTOPTIMIZED;
var sourceArt = this.doc.selection[0];
var clipBounds = sourceArt.visibleBounds;
this.doc.rasterize(sourceArt, clipBounds, this.option
...
Copy link to clipboard
Copied
check this thread for a how to rasterize an object sample
https://community.adobe.com/t5/illustrator-discussions/raster-resolution/m-p/9747492#M88839
and this document for all options you need that are missing from the script
https://ai-scripting.docsforadobe.dev/jsobjref/RasterizeOptions.html
let us know if you get stuck and need more help
Copy link to clipboard
Copied
I managed to create something not quite like I wanted because all the elements are separate photos and I wanted one of the whole graphic. How do I correct this?
// select all
app.executeMenuCommand("selectall");
var Rasterizer = function (resolution) {
this.doc = app.activeDocument;
this.selection = this.doc.selection;
this.options = new RasterizeOptions();
this.options.resolution = resolution || 200;
this.options.transparency = false;
this.options.antiAliasingMethod = AntiAliasingMethod.ARTOPTIMIZED;
};
Rasterizer.prototype.run = function () {
var n = this.selection.length;
for (var i = 0; i < n; i++) {
var sourceArt = this.selection[i];
var clipBounds = sourceArt.visibleBounds;
this.doc.rasterize(sourceArt, clipBounds, this.options);
}
};
var rasterizer = new Rasterizer();
rasterizer.run();
Copy link to clipboard
Copied
I used what I found on the web and managed to make a script that works the way I wanted. It's not the most beautiful, kind of Frankenstein š
If anyone would like to simplify it - I'd be happy to learn something.
// removes everything out of the artboard
app.executeMenuCommand ("selectallinartboard");
app.executeMenuCommand ("Inverse menu item");
app.executeMenuCommand ("clear");
// select all
app.executeMenuCommand("selectall");
// group
app.executeMenuCommand("group");
// rasterize
var Rasterizer = function (resolution) {
this.doc = app.activeDocument;
this.selection = this.doc.selection;
this.options = new RasterizeOptions();
this.options.resolution = resolution || 200;
this.options.transparency = true;
this.options.antiAliasingMethod = AntiAliasingMethod.ARTOPTIMIZED;
};
Rasterizer.prototype.run = function () {
var n = this.selection.length;
for (var i = 0; i < n; i++) {
var sourceArt = this.selection[i];
var clipBounds = sourceArt.visibleBounds;
this.doc.rasterize(sourceArt, clipBounds, this.options);
}
};
var rasterizer = new Rasterizer();
rasterizer.run();
Copy link to clipboard
Copied
Hello @irek289170064v73
Give this a try...
raster = function() {
app.executeMenuCommand("selectall");
app.executeMenuCommand("group");
this.doc = app.activeDocument;
this.options = new RasterizeOptions();
this.options.resolution = 200;
this.options.transparency = true;
this.options.antiAliasingMethod = AntiAliasingMethod.ARTOPTIMIZED;
var sourceArt = this.doc.selection[0];
var clipBounds = sourceArt.visibleBounds;
this.doc.rasterize(sourceArt, clipBounds, this.options);
}
raster();
And as @CarlosCanto stated...
"and this document for all options you need that are missing from the script"
https://ai-scripting.docsforadobe.dev/jsobjref/RasterizeOptions.html
otherwise the defaults will be used for the ones missing.
Regards,
Mike