Right, yes there is this functionality in CS4 - what the OP, myself, and many others want is a way to make it more automatic - like a keyboard shortcut to snap the artboard to selected art, all art, or what have you. If it's in Fireworks, why not have it in Illustrator. At least, if nto a shortcut, a way to script it, or put it in an action would be nice.
wow, such an old post, all the OP and others requests are now possible with CS5.
here you go, for you and other CS4 users
#target Illustrator
// script.name = shrinkABtoFitArt_CS4.jsx;
// script.description = resizes active artboard to fit the the Art (+ margins);
// script.required = one document with at least one piece of art;
// script.parent = carlos canto // 5/3/11;
// script.elegant = false;
if (app.documents.length > 0)
{
//alert("more than 0");
var idoc = app.activeDocument;
var pageItemsCount = idoc.pageItems.length;
if (pageItemsCount>=1)
{
var msg = "Enter Artboard Margins \n";
msg += "\nEnter negative numbers to cancel";
var margins = Number(Window.prompt (msg, 10, "CS4 Shrink Arboard to Fit"));
if (margins>=0)
{
var activeABindex = idoc.artboards.getActiveArtboardIndex();
var newAB = idoc.artboards[activeABindex];
var iartBounds = idoc.visibleBounds;
var ableft = iartBounds[0]-margins;
var abtop = iartBounds[1]+margins;
var abright = iartBounds[2]+margins;
var abbottom = iartBounds[3]-margins;
newAB.artboardRect = [ableft, abtop, abright, abbottom];
var myZoom = idoc.activeView.zoom;
idoc.activeView.zoom = myZoom+.01;
idoc.activeView.zoom = myZoom;
}
else
{
alert("nos vamos");
}
}
else
{
alert("there is no art in the active document");
}
}
else
{
alert ("there are no open documents");
}
I never had CS4 but Illustrator has options for opening files and handling artboards…
convertCropAreaToArboard
convertTilesToArboard
createArtboardWithArtworkBoundingBox // This may be what you want?
preserveLegacyArtboard
You could batch script opening files… even script it to work from bridge as input… I don't use actions so I don't know it these options are available when recording some open file in AI?
#target illustrator
function fitArtboards() {
if (app.documents.length == 0) {
alert('Open a document before running this script');
return;
} else {
for (var i = 0; i < documents.length; i++ ) {
app.activeDocument = documents[i];
app.activeDocument.artboards[0].artboardRect = app.activeDocument.geometricBounds;
redraw();
}
}
}
fitArtboards();
Rhiannon Miller wrote:
CarlosCanto wrote:
wow, such an old post, all the OP and others requests are now possible with CS5.
Sorry Carlos, I have CS5 (and CS5.1) and I'm still unable to record the changing of the artboard size as an Illustrator action. Could you explain how to do this in CS5 please?
Hi Rhiannon, sorry for the confusion, I didn't mean you could record an action in CS5, I meant you could do it manually in CS5.
I'll give it try tomorrow, I have CS5 at work. I'll let you know.
Hi, I've been following this thread and have a similar issue. I'm working in CS4. I believe I have the right script to shrink the artboard to fit my content--thanks, everyone!--but now I'd like to automate the whole thing so that it will open, run the script and save. I've got a few hundred very similar images here and obvs running the script on each individually is overwhelming. I'm not clear why running a script cannot be a recordable action, but so it goes.
Can someone please explain the basics of getting a code to do this? I don't even know--would I run it in Script Editor?
Advice?
Thanks!
Trevor
You can C&P from the post above… If you use the sample by Prepress then it should work with all open documents… Paste into a new document window in the ESTK from there you can test/run with Illustrator as the selected target… or you could save to file what ever you want to call it and file extension '.jsx' drop that in your Illustrator scripts and restart the app…
I would have used visibleBounds over geometricBounds myself but hey ho each to their own…
The question wasn't about whether it's possible, it's about how to record that action into a script. When you record a script it does not record that step in CS5 or earlier. (Not sure if it does in later versions.) To do so you must choose (from Actions menu, as you're recording the script) Insert Menu Item and then choose from the menu Object [sorry I can't remember the name of the command and I don't have CS5 here] something like Fit to Artboard.
North America
Europe, Middle East and Africa
Asia Pacific