Skip to main content
Inspiring
October 5, 2018
Question

Is there a way to paste the File name into the document

  • October 5, 2018
  • 3 replies
  • 697 views

Hello,

Is there a script out there that can add the file name file name within the artboard of illustrator?  If that's possible, I'd like to add the text "Order# " and drop the file extension.  Then place it aligned Left and Bottom to the art.  In a specific font and size.

Does anyone know if/how this could be done?

Thank you!

This topic has been closed for replies.

3 replies

滔周19517892
Participant
October 6, 2018

var content="love";

var font=app.textFonts[0];

var size=12;

var color=getCMYKColor(0,100,100,0);

newGroup = app.activeDocument.groupItems.add();

addText(10,0,content,font,size,color,0).moveToBeginning( newGroup );

addText(0,-10*1,content,font,size,color,45).moveToBeginning( newGroup );

addText(0,-10*2,content,font,size,color,90).moveToBeginning( newGroup );

function addText(x,y,content,font,size,color,rotate){

   var pt=72/25.4;

   var text = app.activeDocument.activeLayer.textFrames.add();

   text.left=x*pt;

   text.top =y*pt;

   text.contents = content;

   text.textRange.characterAttributes.size=size;

   text.rotate(rotate);

   //text.textRange.characterAttributes.textFont = textFonts.getByName(font);
   text.textRange.characterAttributes.textFont = font;

   text.textRange.characterAttributes.fillColor = color;

   //textRef1.createOutline( );
   return text;

}

function getRegColor(){

   var docRef = app.activeDocument;

   var newSpot = docRef.swatches;

   for(var i=0;i<newSpot.length;i++){

   var swatch1 = docRef.swatches[i];

   if(swatch1.color=='[SpotColor]'){

   var spot2 = swatch1.color.spot;

   var colorType2 = spot2.colorType;

   if(colorType2.toString()== "ColorModel.REGISTRATION") {

   regColorIndex=i; }

  }else{

   continue;

  }

  }

   return docRef.swatches[regColorIndex].color;

}

function getCMYKColor(c,m,y,k){

   var color = new CMYKColor();

   color.cyan= c;

   color.magenta = m;

   color.yellow = y;

   color.black = k;

   return color
}

pixxxelschubser
Community Expert
Community Expert
October 6, 2018

Hi

pixxxelschubser
Community Expert
Community Expert
October 5, 2018

place these lines in front of Silly-V​ code

var aTF = app.activeDocument.textFrames.add();

aTF.name = "file_name";

aTF.rotate(90);

aTF.position = [app.activeDocument.artboards[0].artboardRect[0], app.activeDocument.artboards[0].artboardRect[3]];

… and have fun

Silly-V
Legend
October 5, 2018

Hey, just have a text frame wherever you want it with the correct font size, etc in it and ensure it's named a name that we can later reference such as "file_name".

Then you can use:

app.activeDocument.textFrames["file_name"].contents = "Order# " + app.activeDocument.name.replace(".ai", "");