Last active
May 22, 2023 16:37
-
-
Save shivendra14/5147b529001da1458a0017c866f633b9 to your computer and use it in GitHub Desktop.
Illustrator_Scale_Artboard_and_Artwork
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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; | |
} | |
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
change following variable to resize to other dimension!
var requiredABsize = 800; //px