Forked from shivendra14/Illustrator_Scale_Artboard_and_Artwork.jsx
Created
May 22, 2023 16:37
-
-
Save sionta/93f373abb588574c2c15306f168fef7e 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; | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment