Skip to content

Instantly share code, notes, and snippets.

@JohannesDeml
Last active April 5, 2018 14:17
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save JohannesDeml/8b58997c5ed11c7e0baf9ad083910a47 to your computer and use it in GitHub Desktop.
Save JohannesDeml/8b58997c5ed11c7e0baf9ad083910a47 to your computer and use it in GitHub Desktop.
Adobe Illustator script: Creates an artboard for each selected image with the name of the imageFile and its size on the canvas
// ----------------------------------------------------------------------------
// <copyright file="CreateArtboardsForSelectedImages.jsx" company="Supyrb">
// Copyright (c) 2018 Supyrb. All rights reserved.
// </copyright>
// <author>
// Johannes Deml
// send@johannesdeml.com
// </author>
// <summary>
// Creates an artboard for each selected image with the name of the imageFile and its size on the canvas.
// Works only if the image file still exists for the defined path.
// </summary>
// ----------------------------------------------------------------------------
if (app.documents.length > 0) {
var selectedItems = app.activeDocument.selection;
for(var i = 0; i < selectedItems.length; i++) {
var item = selectedItems[i];
var itemtype = item.typename;
// Only support RasterItem and PlacedItem
if(itemtype != "RasterItem" && itemtype != "PlacedItem") {
alert(itemtype);
continue;
}
var filename = itemtype + "ArtBoard";
try {
filename = item.file.name;
filename = filename.substr(0, filename.lastIndexOf("."));
}
catch(e) {
// File does not exist
// TODO: Get name otherwise
}
var artboard = app.activeDocument.artboards.add (item.geometricBounds);
artboard.name = filename;
}
}
else {
alert('Open a document before running this script', 'Error running CreateArtboardsForSelectedImages.jsx');
}
@JohannesDeml
Copy link
Author

JohannesDeml commented Apr 3, 2018

Just save the file to C:\Program Files\Adobe\Adobe Illustrator CC YEAR\Presets\LOCALE\Scripts\Supyrb\CreateArtboardsForSelectedImages.jsx

After restarting illustrator you will get this:
image

For more info on how to setup scripts in adobe illustrator check out this page: https://www.adobe.com/devnet/illustrator/scripting.html
Adobe Forum entry: https://forums.adobe.com/message/10290691#10290691

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment