Auto Rename Artboards Based On Placed Image Filename

Community Beginner ,
Oct 08, 2020 Oct 08, 2020

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!

 

 

TOPICS
Feature request, Import and export, Scripting, Third party plugins

Views

425

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 3 Correct Answers

Adobe Community Professional , Oct 08, 2020 Oct 08, 2020
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...

Likes

Translate

Translate
Enthusiast , Oct 08, 2020 Oct 08, 2020
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; } } }

Likes

Translate

Translate
Enthusiast , Oct 08, 2020 Oct 08, 2020
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.

Likes

Translate

Translate
Adobe Community Professional ,
Oct 08, 2020 Oct 08, 2020

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();

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Oct 08, 2020 Oct 08, 2020

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!

 

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Enthusiast ,
Oct 08, 2020 Oct 08, 2020

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;
    }
  }
}

 

 

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Enthusiast ,
Oct 08, 2020 Oct 08, 2020

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.

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Oct 08, 2020 Oct 08, 2020

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!

 

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Oct 09, 2020 Oct 09, 2020

Copy link to clipboard

Copied

This may work for some but I couldn't get it to work on my end. Thanks!

 

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Feb 02, 2021 Feb 02, 2021

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();

 

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Enthusiast ,
Feb 02, 2021 Feb 02, 2021

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. 

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Feb 02, 2021 Feb 02, 2021

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!Screen Shot 2021-02-02 at 3.29.32 PM.png

 

#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();

 

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Enthusiast ,
Feb 02, 2021 Feb 02, 2021

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?

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Feb 02, 2021 Feb 02, 2021

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"Screen Shot 2021-02-02 at 3.59.54 PM.png

 

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Enthusiast ,
Feb 02, 2021 Feb 02, 2021

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:

https://community.adobe.com/t5/illustrator/find-broken-link-name-using-placeditem-name-property/m-p/... 

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Feb 02, 2021 Feb 02, 2021

Copy link to clipboard

Copied

LATEST

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.

 

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Oct 09, 2020 Oct 09, 2020

Copy link to clipboard

Copied

This worked great. Thanks!

 

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Oct 09, 2020 Oct 09, 2020

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!

 

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Nov 27, 2020 Nov 27, 2020

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:

elinochinjr_1-1606545610949.png

 

 

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Jan 29, 2021 Jan 29, 2021

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. 

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Adobe Community Professional ,
Jan 29, 2021 Jan 29, 2021

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.

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines