Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

resizing width of a selected object.

Explorer ,
Jan 04, 2017 Jan 04, 2017

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.​

TOPICS
Scripting
1.1K
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct answer

Valorous Hero , Jan 04, 2017 Jan 04, 2017

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];

Translate
Adobe
Valorous Hero ,
Jan 04, 2017 Jan 04, 2017

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];

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Mentor ,
Jan 06, 2017 Jan 06, 2017

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.

Screen Shot 2017-01-06 at 10.34.10 AM.jpg

Screen Shot 2017-01-06 at 10.35.19 AM.jpg    

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Jan 06, 2017 Jan 06, 2017

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:

  •   // required: an open document and a selected path item 
  • var myDocument = app.activeDocument; 
  • var selectedObject = myDocument.selection[0]; 
  •  
  • // Get position of selection bounds and create condense ratio 
  • var myBounds = selectedObject.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 = ((rawRepeat - 18) / rawRepeat) * 100;
  • //Identify left edge of repeat 
  • var repeatBounds = app.activeDocument.groupItems['repeat'].geometricBounds; 
  • var r1 = repeatBounds[0]; 
  •  
  • selectedObject.resize(
  •     condenseRatio, // x
  •     100.0, // y
  •     true, // changePositions
  •     true, // changeFillPatterns
  •     true, // changeFillGradients
  •     true, // changeStrokePattern
  •     true , // changeLineWidths
  •     Transformation.LEFT); // scaleAbout
  •    
  • copy();

Turns out my napkin geometry was a bit off and so my condense ratio had to be adjusted, but now it works beautifully.

Thanks.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Valorous Hero ,
Jan 06, 2017 Jan 06, 2017
LATEST

Sweet! Wanna mark as solved then?

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines