Script for rasterize effect at text/ rectangle in illsutrator
Copy link to clipboard
Copied
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
Explore related tutorials & articles
Copy link to clipboard
Copied
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!
Copy link to clipboard
Copied
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
Copy link to clipboard
Copied
It worked for me just now in Ai 2021 Windows!
Copy link to clipboard
Copied
Interesting! I am on a Mac, so could be that, but maybe my code is wrong. Here's what I'm using:
// apply offset path live effect to selected path
var path = app.activeDocument.selection[0];
xmlstring = '<LiveEffect name="Adobe Offset Path"><Dict data="R mlim 4 R ofst 20 I jntp 2 "/></LiveEffect>';
path.applyEffect(xmlstring);
I get this: Runtime Error: Error Code# 24: path.applyEffect is not a function.
Copy link to clipboard
Copied
Hmm, are you able to verify that your path is a selected path? This is not very likely, but you could have a cursor inside a text frame and Illustrator will be treating the .selection object as a text selection.
Otherwise, let's see if anyone else can do a Mac test, hopefully a solution will come.
Copy link to clipboard
Copied
Yes it seems to be normal object and selected. Just drew a rectangle and ran the code with it selected.
Edit: removed call for help, as my issue was solved by Carlos. 🙂
- Mark
Copy link to clipboard
Copied
hi Mark, the problem is your variable name, it should not resemble reserved words (object name in this case)
do
var path2 instead
Copy link to clipboard
Copied
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
Copy link to clipboard
Copied
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.
Copy link to clipboard
Copied
Ha ha!
var problema = 'solved!';
Copy link to clipboard
Copied
jajaja (hahaha in Spanish)
Copy link to clipboard
Copied
Hey Carlos and Silly-V, I have done a few hours of experimenting with this new witchcraft and I'd like to share it. Would it be best to post here or should I make a new topic? I have made a script to help parse the effect markup from a raw .ai document and made a video of the technique. Also a bunch of xml snippets for various live effects. What do you think? I've never really made this kind of contribution before.
- Mark
Copy link to clipboard
Copied
Hi @m1b . Please do share. I think if you make a new topic it might be more easily seen/found.
Copy link to clipboard
Copied
Yes, this will be extremely useful for everyone, thanks!
Copy link to clipboard
Copied
Hi Mark, I agree, it will be useful for everyone. It might be best to start a new thread.
Copy link to clipboard
Copied
Thanks, I started a new thread here: Scripting Live Effects. If you get a chance have a look and tell me what errors to fix! - Mark
Copy link to clipboard
Copied
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.
Copy link to clipboard
Copied
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..
Copy link to clipboard
Copied
applyEffect() only works from CS6 onwards.
Copy link to clipboard
Copied
Hi femkeblanco,
U r correct, below attached image for reference that I got from this thread "Rasterize .pngs in document and move to specific layer", solve by Silly-V..
Thanks everyone..
 
Copy link to clipboard
Copied
Oh! I see you are happy with the document.rasterize() method. I was on the wrong track because I read "the effect rasterize" in your question and assumed you needed a live effect version. Oops.
Glad you sorted it out. 🙂

