Saturday, October 29, 2011

Expand a raster tracing object

This week Hugo Tait sent me an excellent question about how to expand a tracing object.

Unfortunately, there wasn't much of an example in the javascript guide.
It took a little experimentation, but I came up with the following script, and thought I'd share it with all of you here. This will take the current selected Raster object (embedded not placed) and convert it into 4 color geometry.

var doc = activeDocument;
var obj = doc.selection[0];
var r = obj.trace();
var options = r.tracing.tracingOptions;
options.tracingMode = TracingModeType.TRACINGMODECOLOR;
options.ignoreWhite=true;
options.maxColors=4;
redraw();
r.tracing.expandTracing();

cheers,
-J

2 comments:

Mentifex said...

Oh, gee, I found this excellent JS4AI blog when I was searching for JavaScript for Artificial Intelligence. Oh well, it's still a beautiful blog. Best of luck! -Arthur T. Murray (Mentifex)

John said...

Sometimes I think Illustrator has a mind of it's own. :)
It would be interesting to see some artificial intelligence experiments adapted to illustrator. Let me know if you have any ideas.