1 person found this helpful
The selection object in Illustrator scripting in an array, of sorts, so you have to pick one element in it to resize.
var selectedObject = myDocument.selection;
Silly's answer is absolutely correct. 'resize' is not a method of the array object. so you have to iterate the items in the array, however you have to be careful about that as well because if you simply iterate each item and reduce it's width, you're going to change the relative position of everything on the page. in order to keep the proportions of everything, you're going to need to group everything together before you resize. See the two attached images. For the 'after' image, i scaled each item's width by 50% to make the change more pronounced.
Didn't get a chance to implement this yesterday, but that's exactly what it was (as you clearly knew)... here's the new and improved script:
- // required: an open document and a selected path item
- var myDocument = app.activeDocument;
- var selectedObject = myDocument.selection;
- // Get position of selection bounds and create condense ratio
- var myBounds = selectedObject.geometricBounds;
- var x1 = myBounds;
- var x2 = myBounds;
- var rawRepeat = (r1 - x1);
- var rawGap = (r1 - x2);
- var rawPrintWidth = myBounds - myBounds;
- var condenseRatio = ((rawRepeat - 18) / rawRepeat) * 100;
- //Identify left edge of repeat
- var repeatBounds = app.activeDocument.groupItems['repeat'].geometricBounds;
- var r1 = repeatBounds;
- condenseRatio, // x
- 100.0, // y
- true, // changePositions
- true, // changeFillPatterns
- true, // changeFillGradients
- true, // changeStrokePattern
- true , // changeLineWidths
- Transformation.LEFT); // scaleAbout
Turns out my napkin geometry was a bit off and so my condense ratio had to be adjusted, but now it works beautifully.
Sweet! Wanna mark as solved then?