Copy link to clipboard
Copied
Hello,
Is there a script for when you put a linked image will insert a text with the filename of the linked and rename artboard at the same time. I don't know how to script 😞
Thank you. This will save my workflow!
2 Correct answers
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") {
var name1 = decodeURI(selection[j].file.name).replace(/\.[^\.]+$/, "");
doc.artboards[i].name = name1;
var d = doc.artboards[i].artboardRect;
var rect1 = doc.pathItems.rectangle(d[1] - 10, d[0] + 10, (d[2] - d[0]) - 20
...
OK. So you want the document name first. Try this:
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].artboard
...
Explore related tutorials & articles
Copy link to clipboard
Copied
Insert text where?
Copy link to clipboard
Copied
Top left corner, please see image. thank you
Copy link to clipboard
Copied
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") {
var name1 = decodeURI(selection[j].file.name).replace(/\.[^\.]+$/, "");
doc.artboards[i].name = name1;
var d = doc.artboards[i].artboardRect;
var rect1 = doc.pathItems.rectangle(d[1] - 10, d[0] + 10, (d[2] - d[0]) - 20, 20);
var text1 = doc.textFrames.areaText(rect1);
text1.contents = name1;
break;
}
}
}
Copy link to clipboard
Copied
Wow!! This is perfect! Thank you so much!!
Copy link to clipboard
Copied
Can I add one more? What if I like to add the Filename itselft?
Sample 1:
Filename - Linked name
Sample 2:
Filename
Linked name
Copy link to clipboard
Copied
I am unsure what you are asking. Your options are
(a) the name of the placed item itself, as it appears in the layers panel
alert( app.activeDocument.placedItems[0].name );
(b) the name of the file the placed item is linked to.
alert( app.activeDocument.placedItems[0].file.name );
Copy link to clipboard
Copied
sorry, I don't know what to do with that code 😞
This is what I want look like
Copy link to clipboard
Copied
OK. So you want the document name first. Try this:
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 rect1 = doc.pathItems.rectangle(d[1] - 10, d[0] + 10, (d[2] - d[0]) - 20, 40);
var text1 = doc.textFrames.areaText(rect1);
text1.contents = name1 + " - " + name2;
break;
}
}
}
If you want them on two separate lines, change the line before last to
text1.contents = name1 + "\r" + name2;
Copy link to clipboard
Copied
working!!!! Thank you thank you so much!! This is lifesaver!

