Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 3 You must be signed in to star a gist
  • Fork 3 You must be signed in to fork a gist
  • Save shivendra14/5147b529001da1458a0017c866f633b9 to your computer and use it in GitHub Desktop.
Save shivendra14/5147b529001da1458a0017c866f633b9 to your computer and use it in GitHub Desktop.
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
Copy link
Author

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

@azisher
Copy link

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