Copy link to clipboard
Copied
I have a simple problem, but I haven't found a solution it.
I have a object and rectangle grouped together and want to scale the object proportionally and have it centered inside the rectangle.
I'm looking for an automated solution to this because I have a lot of objects that need to be scaled and centered like this.
The art I'm working with is similar to this.

here's some pseudo code that may help..
var icon = the icon artwork
var background = the background square
var iconDimension,scale;
//get the largest dimension of the icon
if icon.width > icon.height
iconDimension = icon.width;
else
iconDimension = icon.height;
//get the scale percentage
if iconDimension < background.width
scale = (iconDimension / background.width) * 100
else
scale = (background.width / iconDimension) * 100
//get 80% of the scale
scale = scale*.8;
//resize the icon
icon.resize(
...Copy link to clipboard
Copied
You simply do pageItem.resize(w, h).
#target illustrator
function test(){
var doc = app.activeDocument;
var obj = doc.pathItems.getByName("obj");
obj.resize(150, 150);
};
test();
Before:

After:
Copy link to clipboard
Copied
Silly-V thanks for response !
But I need different solution. I have different sizes of vector objects in artboard. I want to add each of them to groupped standart sized rectangles and make the icons be center and fit the rectangle. I just need script to make below " Before - After " thing.
Before:

After:

Copy link to clipboard
Copied
How do you decide what % of height is to be smaller than the rectangle, which gives it such amount of padding room?
Copy link to clipboard
Copied
I guess icon's height has to be 80% of rectangle's height. Actually I want to resize all my icons in artboard proportionally / keeping the aspect ratio. Let's say my rectangle should be 500x500px. My icon's height should be not more than 400px.
Copy link to clipboard
Copied
here's some pseudo code that may help..
var icon = the icon artwork
var background = the background square
var iconDimension,scale;
//get the largest dimension of the icon
if icon.width > icon.height
iconDimension = icon.width;
else
iconDimension = icon.height;
//get the scale percentage
if iconDimension < background.width
scale = (iconDimension / background.width) * 100
else
scale = (background.width / iconDimension) * 100
//get 80% of the scale
scale = scale*.8;
//resize the icon
icon.resize(scale,scale);
//make sure the icon is still centered in the background box
icon.left = (background.left + background.width/2) - icon.width/2
icon.top = (background.top - background.width/2) + icon.height/2
Find more inspiration, events, and resources on the new Adobe Community
Explore Now