Skip to main content
Participating Frequently
December 13, 2010
Question

resize method with Javascript in Illustrator CS4

  • December 13, 2010
  • 2 replies
  • 4262 views

var objectBounds = docRef.visibleBounds;

var W = objectBounds[2] - objectBounds[0]; //figures the width

var H = objectBounds[1] - objectBounds[3]; //figures the height

// W & H are reporting the size in points ... convert to picas

var picaW = W / 12;

var picaH = H / 12;

// do the math for the correct column width: settings / width = percentage in decimal; multiply by 100 to get the decimal place in the right spot.

var endWidth

var percentageX = Math.round((endWidth / picaW) * 100);

var percentageY = percentageX;

for (var a=0; a<docRef.layers.length; a++){

     var layerRef = docRef.layers;

     layerRef.hasSelectedArtwork=true;   // select all

     // now to resize based on the percentage

     layerRef.pageItem.resize(percentageX, percentageY);

}

The width and height are coming out fine. But in this last line, that resize is just not working. When I run it I get an error that says: undefined is not an object.

The syntax must be wrong ... any ideas?

Thanks in advance!

This topic has been closed for replies.

2 replies

linz80Author
Participating Frequently
December 13, 2010

var endWidth = 20;

*just a typo when posting...

Muppet_Mark-QAl63s
Inspiring
December 13, 2010

Im not sure I understand what you are doing here. I think if you are going to select items then you should process the document selection. (Im no fan of selecting in script). Else just target your items without selecting. Are you hoping 'pageItem' is going to resize all the layer objects? Or is that a typo and should be 'pageItems[0]' plural… by index

linz80Author
Participating Frequently
December 13, 2010

Basically I just need to resize an image. If selecting isn't the way to go then that's fine, I'm just trying things...

Do you know how to use .resize?

Larry G. Schneider
Community Expert
Community Expert
December 13, 2010

Where are you running it from? If from the ESTK, make sure yhou have targeted Illustrator in the application dropdown above the script window.

linz80Author
Participating Frequently
December 13, 2010

Yes, running it in ESTK and yes, targeting Illustrator. (This is just part of my script.)

Thanks.