Insert/Rename Artboard by linked image

Explorer ,
Nov 27, 2020 Nov 27, 2020

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 😞

 

elinochinjr_1-1606544995228.png

 

 

 

Thank you. This will save my workflow!

TOPICS
Feature request, How to, Scripting

Views

194

Likes

translate

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 2 Correct Answers

Enthusiast , Nov 27, 2020 Nov 27, 2020
 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...

Likes

translate

Translate

Translate
Enthusiast , Dec 01, 2020 Dec 01, 2020
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...

Likes

translate

Translate

Translate
Enthusiast ,
Nov 27, 2020 Nov 27, 2020

Copy link to clipboard

Copied

Insert text where? 

Likes

translate

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

Top left corner, please see image. thank you

Likes

translate

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 ,
Nov 27, 2020 Nov 27, 2020

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

 

Likes

translate

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 28, 2020 Nov 28, 2020

Copy link to clipboard

Copied

Wow!! This is perfect! Thank you so much!!

Likes

translate

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 28, 2020 Nov 28, 2020

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

Likes

translate

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 ,
Nov 28, 2020 Nov 28, 2020

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

 

Likes

translate

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 30, 2020 Nov 30, 2020

Copy link to clipboard

Copied

sorry, I don't know what to do with that code 😞

This is what I want look like

elinochinjr_0-1606794295839.png

 

Likes

translate

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 ,
Dec 01, 2020 Dec 01, 2020

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;

 

Likes

translate

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 ,
Dec 01, 2020 Dec 01, 2020

Copy link to clipboard

Copied

working!!!! Thank you thank you so much!! This is lifesaver!

Likes

translate

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