Skip to main content
Known Participant
November 28, 2020
Answered

Insert/Rename Artboard by linked image

  • November 28, 2020
  • 2 replies
  • 1027 views

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!

This topic has been closed for replies.
Correct answer femkeblanco

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

This is what I want look like

 


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;

 

2 replies

femkeblanco
Legend
November 28, 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;
    }
  }
}

 

Known Participant
November 28, 2020

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

femkeblanco
Legend
November 28, 2020

Insert text where? 

Known Participant
November 28, 2020

Top left corner, please see image. thank you