Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
0

Insert/Rename Artboard by linked image

Explorer ,
Nov 27, 2020 Nov 27, 2020

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.pngexpand image

 

 

 

Thank you. This will save my workflow!

TOPICS
Feature request , Scripting
761
Translate
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

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

Insert text where? 

Translate
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

Top left corner, please see image. thank you

Translate
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
Guide ,
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, 20);
      var text1 = doc.textFrames.areaText(rect1);
      text1.contents = name1;
      break;
    }
  }
}

 

Translate
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

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

Translate
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

Can I add one more? What if I like to add the Filename itselft?

 

Sample 1:

Filename - Linked name

 

Sample 2:

Filename

Linked name

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

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

 

Translate
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

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

This is what I want look like

elinochinjr_0-1606794295839.pngexpand image

 

Translate
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
Guide ,
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].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;

 

Translate
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
LATEST

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

Translate
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