Copy link to clipboard
Copied
Is there a way wether it be through a script or third party plugin to auto rename a series of artboards within a file based on the placed image within each artboard?
Scenario: If I am doing t-shirt mockups and have 3 artboards each with a different shirt images and want to export jpgs of each artboard and have them named based off of the filenames of each shirt image. Would be very convenient to have the artboards renamed automatically based on the placed shirt image filename vs manually changing the name of each artboard.
Thanks!
This should do the trick:
#target illustrator
function test(){
var doc = app.activeDocument;
var boards = doc.artboards;
var thisBoard, artItemOnBoard, placedItemName;
for (var i = 0; i < boards.length; i++) {
thisBoard = boards[i];
doc.artboards.setActiveArtboardIndex(i);
doc.selection = null;
doc.selectObjectsOnActiveArtboard();
for (var j = 0; j < doc.selection.length; j++) {
artItemOnBoard = doc.selection[j];
if (artItemOnBoard.typename == "PlacedItem") {
placedItem
...
You beat me to it, Silly-V. This is what I cam up with:
var doc = app.activeDocument;
for (var i = 0; i < doc.artboards.length; i++) {
doc.artboards.setActiveArtboardIndex(i);
doc.selectObjectsOnActiveArtboard();
for (var j = 0; j < selection.length; j++) {
if (selection[j].typename == "PlacedItem") {
doc.artboards[i].name = selection[j].name;
}
}
}
Copy and paste it in a jsx file. (You can create a txt file and change the extension to jsx.)
Then, while your document is open in Illustrator, go to File > Scripts > Other Script (Ctrl+F12). Find your script and open it.
Copy link to clipboard
Copied
This should do the trick:
#target illustrator
function test(){
var doc = app.activeDocument;
var boards = doc.artboards;
var thisBoard, artItemOnBoard, placedItemName;
for (var i = 0; i < boards.length; i++) {
thisBoard = boards[i];
doc.artboards.setActiveArtboardIndex(i);
doc.selection = null;
doc.selectObjectsOnActiveArtboard();
for (var j = 0; j < doc.selection.length; j++) {
artItemOnBoard = doc.selection[j];
if (artItemOnBoard.typename == "PlacedItem") {
placedItemName = decodeURI(artItemOnBoard.file.name).replace(/\.[^\.]+$/, "");
thisBoard.name = placedItemName;
}
}
}
}
test();
Copy link to clipboard
Copied
Sorry, what is the best way to add this in? I have used scripts before but previously just downloaded them. Thanks for your help!
Copy link to clipboard
Copied
You beat me to it, Silly-V. This is what I cam up with:
var doc = app.activeDocument;
for (var i = 0; i < doc.artboards.length; i++) {
doc.artboards.setActiveArtboardIndex(i);
doc.selectObjectsOnActiveArtboard();
for (var j = 0; j < selection.length; j++) {
if (selection[j].typename == "PlacedItem") {
doc.artboards[i].name = selection[j].name;
}
}
}
Copy link to clipboard
Copied
Copy and paste it in a jsx file. (You can create a txt file and change the extension to jsx.)
Then, while your document is open in Illustrator, go to File > Scripts > Other Script (Ctrl+F12). Find your script and open it.
Copy link to clipboard
Copied
You both are awesome. Thanks!
I got Silly-V's script to work but couldn't get femkeblanco's to work.
Appreciate the quick fix to this!
Thanks!
Copy link to clipboard
Copied
This may work for some but I couldn't get it to work on my end. Thanks!
Copy link to clipboard
Copied
Is there a way this script can be modified to work on both embedded and linked images? Currently this script only seems to work for linked images on my end. If not both is it possible to have two different scripts to work accordingly?
#target illustrator
function test(){
var doc = app.activeDocument;
var boards = doc.artboards;
var thisBoard, artItemOnBoard, placedItemName;
for (var i = 0; i < boards.length; i++) {
thisBoard = boards[i];
doc.artboards.setActiveArtboardIndex(i);
doc.selection = null;
doc.selectObjectsOnActiveArtboard();
for (var j = 0; j < doc.selection.length; j++) {
artItemOnBoard = doc.selection[j];
if (artItemOnBoard.typename == "PlacedItem") {
placedItemName = decodeURI(artItemOnBoard.file.name).replace(/\.[^\.]+$/, "");
thisBoard.name = placedItemName;
}
}
}
}
test();
Copy link to clipboard
Copied
Is your embedded image named (as it appears in the Layers panel)? If so, try adding this above the third curly bracket from the bottom:
if (artItemOnBoard.typename == "RasterItem" && artItemOnBoard.embedded == true) {
placedItemName = artItemOnBoard.name;
thisBoard.name = placedItemName;
}
If your image is unnamed, nothing will happen.
Copy link to clipboard
Copied
Attached is screenshot.When I use the script above it only works if the images/links are not embedded. Screenshot shows how the individual layers, artboards, and links are named. Not sure what you mean by "Is your embeeded images named (as it appears in the Layers panel). Here is how I have the script now and still is not working on the embedded links but works good on the unembeded links. Appreciate your help!
#target illustrator
function test(){
var doc = app.activeDocument;
var boards = doc.artboards;
var thisBoard, artItemOnBoard, placedItemName;
for (var i = 0; i < boards.length; i++) {
thisBoard = boards[i];
doc.artboards.setActiveArtboardIndex(i);
doc.selection = null;
doc.selectObjectsOnActiveArtboard();
for (var j = 0; j < doc.selection.length; j++) {
artItemOnBoard = doc.selection[j];
if (artItemOnBoard.typename == "PlacedItem") {
placedItemName = decodeURI(artItemOnBoard.file.name).replace(/\.[^\.]+$/, "");
thisBoard.name = placedItemName;
}if (artItemOnBoard.typename == "RasterItem" && artItemOnBoard.embedded == true) {
placedItemName = artItemOnBoard.name;
thisBoard.name = placedItemName;
}
}
}
}
test();
Copy link to clipboard
Copied
In the Layers panel, can you click the toggle arrow to expand Layer 1, to show the items wihtin the layer?
Copy link to clipboard
Copied
Please see attached. I created a new file. I noticed the name shows up under the layer if it is a photoshop file but if it is a jpg is says "linked file"
Copy link to clipboard
Copied
So, the images in the Layers panel between the angle brackets are unnamed, which is why nothing happens. Embedding broke the link to the file, so you can't use the file name either, at least directly. There may be a way to use the file name, but I've not looked into it. Maybe someone else would be able to help you with this:
Copy link to clipboard
Copied
On the file with the most recent screenshot none of the images were embedded yet and if I run the script it works. If I go ahead an embed the images the script doesn't work. When I embed the link the jpg layer names change to <image> and the psd layer name is still pixelicon.psd. Thanks for checking into this. It really isn't a huge priority as I would just use the script before embedding when needed.
Copy link to clipboard
Copied
This worked great. Thanks!
Copy link to clipboard
Copied
Correction: Both scripts work! I tried again and made a new script file from femkeblanco's script and is working now so I may have missed something when I copied the text originally.
The difference that I am noticing between the two is that Silly-V's script does not include the filename extension in the artboard name. Femkeblanco's script does include the filename extension in the artboard name.
Both versions will be useful for me in the future and wanted to pass this along for anyone that may prefer one over the other.
Thanks again for the quick solution to this!
Copy link to clipboard
Copied
Hello,
This works for me perfectly!!
But can you also add text filename base on linked image name?
for example:
Copy link to clipboard
Copied
This is really awesome. Is it possible to rename the arboard based on a paragraph style or character style. It would come in handy with variable data for business cards where the front and back are exported as separate pdf files.
Copy link to clipboard
Copied
That sounds quite possible, but I want to ask how a paragraph or character style will be used to help your cause. I may not be as imaginative as I hope, it seems that if you are going to utilize scripting to rename an artboard to a name of an artistic style utility, it may just be more straightforward to simply script the exporting of your PDF files to instantly go where they need to with just the right name all in one go.
Copy link to clipboard
Copied
Hello,
Again, Thank you for this wonderful script you made for me.
If possible, I want to make a minor change, I really don't know how to code.
The pointText start from the TOP LEFT corner, I just want to make it start at the BOTTOM LEFT corner, that's all.
This is the current script.
var doc = app.activeDocument;
var name1 = app.activeDocument.name;
for (var i = 0; i < doc.artboards.length; i++) {
doc.artboards.setActiveArtboardIndex(i);
doc.selectObjectsOnActiveArtboard();
for (var j = 0; j < selection.length; j++) {
if (selection[j].typename == "PlacedItem") {
var name2 = decodeURI(selection[j].file.name).replace(/\.[^\.]+$/, "");
doc.artboards[i].name = name2;
var d = doc.artboards[i].artboardRect;
var text1 = doc.textFrames.pointText([d[0] + 20, d[1] - 20]);
text1.contents = name1 + " - " + name2;
text1.textRange.characterAttributes.size = 8;
text1.paragraphs[0].paragraphAttributes.justification = Justification.LEFT;
break;
}
}
}
Please see image for reference:
Thank you very much!
Copy link to clipboard
Copied
var doc = app.activeDocument;
var name1 = app.activeDocument.name;
for (var i = 0; i < doc.artboards.length; i++) {
doc.artboards.setActiveArtboardIndex(i);
doc.selectObjectsOnActiveArtboard();
for (var j = 0; j < selection.length; j++) {
if (selection[j].typename == "PlacedItem") {
var name2 = decodeURI(selection[j].file.name).replace(/\.[^\.]+$/, "");
doc.artboards[i].name = name2;
var d = doc.artboards[i].artboardRect;
var text1 = doc.textFrames.pointText([d[0] + 20, d[3] + 20]);
text1.contents = name1 + " - " + name2;
text1.textRange.characterAttributes.size = 8;
text1.paragraphs[0].paragraphAttributes.justification = Justification.LEFT;
break;
}
}
}
Copy link to clipboard
Copied
This is the script that has that has worked great for me in regard to naming artboards based on unembedded images within them:
#target illustrator
function test(){
var doc = app.activeDocument;
var boards = doc.artboards;
var thisBoard, artItemOnBoard, placedItemName;
for (var i = 0; i < boards.length; i++) {
thisBoard = boards[i];
doc.artboards.setActiveArtboardIndex(i);
doc.selection = null;
doc.selectObjectsOnActiveArtboard();
for (var j = 0; j < doc.selection.length; j++) {
artItemOnBoard = doc.selection[j];
if (artItemOnBoard.typename == "PlacedItem") {
placedItemName = decodeURI(artItemOnBoard.file.name).replace(/\.[^\.]+$/, "");
thisBoard.name = placedItemName;
}
}
}
}
test();
I do occasionally get the error:
Error 9062: There is no file associated with this item
Line: 14
-> placedItemName =
decodeURI(artItemOnBoard.file.name).replace(/\.[^\.]+$/,"");
If I quit illustrator and reopen I get the same error.
If I restart the mac and open the same file with the unembedded images it works great. Any idea how to fix this without restarting?
I still can't get it to work with embedded images but that is minor.