Last active
April 5, 2018 14:17
-
-
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
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
// ---------------------------------------------------------------------------- | |
// <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'); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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:
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