Skip to main content
Participating Frequently
January 7, 2021
Question

Script for rasterize effect at text/ rectangle in illsutrator

  • January 7, 2021
  • 3 replies
  • 2039 views

Dear All, I have tried to make an script for create the effect rasterize in illustrator, I tried this command "rasterizeOptions", is that true? If u have any idea, so please help me.. Thank you

This topic has been closed for replies.

3 replies

m1b
Community Expert
Community Expert
January 11, 2021

Hi rikoc40685425, thanks to heaps of help from Silly-V and Carlos, I've just been introduced to the applyEffect method and I've put together a quick script that might do what you need. Let me know if it works for you. - Mark

 

 

// select an object and this will apply the rasterize live effect

var dpi = 30;
var antialiasing = false;
var typeOptimizedAntialiasing = false; // if false, will use 'art optimized'
var transparentBackground = true;
var paddingAroundInPts = 0;
var colrIndex = 1;  // 0 = RGB, 1 = CMYK, 2 = Grayscale, 3 = Bitmap
var clipMask = false;

var rasterizeXML = '<LiveEffect name="Adobe Rasterize"><Dict data="I colr #colr# B alis #alis# I dpi. #dpi# B mask #mask# R padd #padd# I optn #optn# "/></LiveEffect>';

rasterizeXML = rasterizeXML
    .replace(/#colr#/, colrIndex + (transparentBackground ? 4 : 0))
    .replace(/#alis#/, antialiasing ? 1 : 0)
    .replace(/#dpi#/, Math.round(dpi))
    .replace(/#mask#/, clipMask ? 1 : 0)
    .replace(/#padd#/, paddingAroundInPts)
    .replace(/#optn#/, typeOptimizedAntialiasing ? 16 : 0);

var item = app.activeDocument.selection[0];
item.applyEffect(rasterizeXML);

 

 

Edit: added other colour models.

Participating Frequently
January 19, 2021

Hi m1b, CarlosCanto & Silly-V, ..

 

Im sorry for late reply..

 

I've seens ur new thread also.. Its very useful, very good..

 

For AI CC2015 its work perfectly,

But, actually I use AI CS2014 and its not working, the problem same like ur first reply, the variable name its not a function.. I have tried to use the unique name, like path2 also, but still not working..

 

My conclution, live effect is not working for cs4, could u help me once again, to solve this problem..

 Appreciated ur creation, thanks..

 

femkeblanco
Legend
January 19, 2021

applyEffect() only works from CS6 onwards.  

CarlosCanto
Community Expert
Community Expert
January 11, 2021

hi Mark, the problem is your variable name, it should not resemble reserved words (object name in this case)

 

do

var path2 instead

m1b
Community Expert
Community Expert
January 11, 2021

Ah! Yes that was my problem. Thank you Carlos! I've been warned before about doing that before (@femkeblanco!) and I didn't see it this time. I've been using other languages were the idiom is to use the property name as a local variable. I must remember that ExtendScript has very lax variable scoping.

 

- Mark

CarlosCanto
Community Expert
Community Expert
January 11, 2021

it happens, I used to have the same problem but couldn't understand why some variable names raised errors. My solution? I named all my variables in Spanish Lol.

Silly-V
Legend
January 7, 2021

The Rasterize effect is a very powerful Illustrator feature indeed. You could save a graphic style featuring this effect and easily apply it via script, but that requires some document to be saved in a pre-determined place which has that graphic style inside applied to some shape you can copy and paste between documents so as to bring in the graphic style.
Otherwise, please take a look at this thread which elucidates some on the Apply Effect XML scripting method that can add live effects to things: https://community.adobe.com/t5/illustrator/pageitem-applyeffect-liveeffectxml/m-p/7315221?page=1

 

If you perform experimentations with the live effect XML, we would like to know your findings so please post them here if you go that route!

m1b
Community Expert
Community Expert
January 7, 2021

Hi Silly-V, I was very interested to read the thread you linked, but when I try it (in CC2021) it appears that the applyEffect(xml) method is missing! Is this just me? - Mark

Silly-V
Legend
January 8, 2021

It worked for me just now in Ai 2021 Windows!