Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Illustrator_Scale_Artboard_and_Artwork
#target Illustrator
var requiredABsize = 1700; //px
var activeDoc = app.activeDocument;
var abActive = activeDoc.artboards[ activeDoc.artboards.getActiveArtboardIndex() ];
var abProps = getArtboardBounds(abActive);
var scale = findRequiredScale(abProps);
if (scale > 1)
{
// select all items
var items = activeDoc.pageItems;
for(var i = 0;i < items.length;i++)
{
items[i].selected = true;
}
var selection = activeDoc.selection;
// Check if anything is selected:
if (selection.length > 0)
{
// Loop over selected items:
for (i = 0; i < selection.length; i++)
{
selection[i].resize (scale*100, scale*100, true, true, true, true, scale*100, Transformation.DOCUMENTORIGIN);
}
}
activeDoc.fitArtboardToSelectedArt(activeDoc.artboards.getActiveArtboardIndex());
app.executeMenuCommand("fitall");
}
// Artboard bounds helper (used above):
function getArtboardBounds(artboard) {
var bounds = artboard.artboardRect,
left = bounds[0],
top = bounds[1],
right = bounds[2],
bottom = bounds[3],
width = right - left,
height = top - bottom,
props = {
left : left,
top : top,
width : width,
height : height
};
return props;
}
function findRequiredScale(props) {
var scale = Math.min(requiredABsize / props.height, requiredABsize / props.width);
if (scale >1)
return scale;
else
return 1;
}
@shivendra14

This comment has been minimized.

Copy link
Owner Author

@shivendra14 shivendra14 commented Sep 13, 2017

change following variable to resize to other dimension!
var requiredABsize = 800; //px

@azisher

This comment has been minimized.

Copy link

@azisher azisher commented May 31, 2019

is this script work for scale down?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment