Copy link to clipboard
Copied
Trying to get a very simple script to adjust for the slight distortion that happens when a printing plate is wrapped around the print cylinder. Basically I need to condense the image width wise only (not the height) so it will compress something like 95-98% of it's original width but the height will be the same.
I tried to make a fairly basic script to do this, but it keeps telling me "selectedObject.resize is not a function". Ultimately my idea was to create a variable called condenseRatio that would be the percentage I would reduce the width by, because not every plate would reduce by the same percentage. The distortion changes based on which print cylinder is chosen, so wherever the left x value of the repeating image is determines what percentage the image will need to be condensed. Currently I've just got the resize set to 90% of width just to see if I can get it going, and worry about using a variable number there later. So far, no go.
Here's what I've cobbled together:
// required: an open document and a selected path item
var myDocument = app.activeDocument;
var selectedObject = myDocument.selection;
//Identify left edge of repeat
var repeatBounds = app.activeDocument.groupItems['repeat'].geometricBounds;
var r1 = repeatBounds[0];
// Get position of selection bounds and create condense ratio
var myBounds = selectedObject[0].geometricBounds;
var x1 = myBounds[0];
var x2 = myBounds[2];
var rawRepeat = (r1 - x1);
var rawGap = (r1 - x2);
var rawPrintWidth = myBounds[2] - myBounds[0];
var condenseRatio = (rawPrintWidth / rawRepeat) * 100;
selectedObject.resize(
90.0, // x
100.0, // y
true, // changePositions
true, // changeFillPatterns
true, // changeFillGradients
true, // changeStrokePattern
true , // changeLineWidths
undefined); // scaleAbout
Any help on what I'm doing wrong would be greatly appreciated.
Thanks in advance.​
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[0];
Copy link to clipboard
Copied
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[0];
Copy link to clipboard
Copied
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.

Copy link to clipboard
Copied
Thanks Silly!
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:
Turns out my napkin geometry was a bit off and so my condense ratio had to be adjusted, but now it works beautifully.
Thanks.
Copy link to clipboard
Copied
Sweet! Wanna mark as solved then?
Get ready! An upgraded Adobe Community experience is coming in January.
Learn more