Copy link to clipboard
Copied
Hello All,
I need a script to reduce the size of the artboard to the size of the artwork. All the items in the artwork are grouped.
Whether it is possible to do with script. If possible, please some help me to figure out the script.
Example images:
Regards,
Vaithiyanathan J
Copy link to clipboard
Copied
hey @Surya24
check this!
var i, ii, doc, count, itemList, countArtboards, artboardIndex;
doc = app.activeDocument;
countArtboards = doc.artboards.length;
for (ii = countArtboards-1; ii >= 0; ii--) {
artboardIndex = doc.artboards.setActiveArtboardIndex(ii);
doc.selectObjectsOnActiveArtboard();
app.executeMenuCommand ("Fit Artboard to selected Art");
}
app.executeMenuCommand ("fitall");
doc.selection = null;
app.redraw();
Copy link to clipboard
Copied
Hello GerssonDelgado,
Thanks for the script, one small thing while artboard resizing, the aboard size was not exactly matching with size of artwork.
For Example:
Artwork size is width = 2.64" and height = 1.14". while am running the script the artboard size was increased to width = 2.65" and height = 1.15" not exactly matching the size. any option to match exact size.
Note: 0.01" additionally added to width and height of artboard size.
Copy link to clipboard
Copied
Is by any chance Use Preview Bounds checked in your AI Preferences? If it is, try it without this being checked.
Copy link to clipboard
Copied
You know there's a command for this in Illy right?
I have it set with a keyboard short cut, I use it many times a day...
Copy link to clipboard
Copied
An alternative approach (I don't know if it will prove any better):
// select items
app.executeMenuCommand("group");
var group = app.activeDocument.selection[0];
var AB = app.activeDocument.artboards[0]
AB.artboardRect = [
group.left, group.top,
group.left + group.width, group.top - group.height
];
app.executeMenuCommand("ungroup");
Copy link to clipboard
Copied
you can try using executeMenuCommand() with one of the following arguments:
"Fit Artboard to artwork bounds"
or
"Fit Artboard to selected Art"