Illustrator scripting: resize that works like transform tool in illustrator
I'm writing a script for Illustrator CS5 to resize my artwork (and artboards and a whole lot of other stuff in a batch).
I scale this down to 20%:
And I get this (which is fine):
Now, when I use the resize() or transform() functions in Illustrator's scripting I get this:
The simple script to reproduce:
var doc = app.activeDocument; var item = doc.pageItems; item.resize( 20.0, // x 20.0, // y true, // changePositions true, // changeFillPatterns true, // changeFillGradients true, // changeStrokePattern true , // changeLineWidths undefined); // scaleAbout
I have tried playing around with the parameters to resize() but nothing comes close to the transform dialog in Illustrator.
The original .ai file can be downloaded from here.
Turns out that the (badly named IMHO) "changeLineWidths" parameter is not a boolean but a scaling factor just like the x and y parameters.
So this is solved like this:
var scale = 20; // scale down to 20% item.resize( scale , // x scale , // y true, // changePositions true, // changeFillPatterns true, // changeFillGradients true, // changeStrokePattern scale , // changeLineWidths <---- NOTE THIS undefined); // scaleAbout
(IMHO "changeLineWidths" should be named "scaleLineWidths" just like the first two are named "scaleX" and "scaleY" in the documentation.)
Hope this helps someone else!