• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
0

script that rasterizes selected elements to a single image in Illustrator

Community Beginner ,
Mar 18, 2023 Mar 18, 2023

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

TOPICS
Scripting

Views

724

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 2 Correct answers

Community Expert , Mar 18, 2023 Mar 18, 2023

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

Votes

Translate

Translate
Advisor , Mar 18, 2023 Mar 18, 2023

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
...

Votes

Translate

Translate
Adobe
Community Expert ,
Mar 18, 2023 Mar 18, 2023

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

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Mar 18, 2023 Mar 18, 2023

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

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Mar 18, 2023 Mar 18, 2023

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

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Advisor ,
Mar 18, 2023 Mar 18, 2023

Copy link to clipboard

Copied

LATEST

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

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines