Skip to main content
zblj
Participating Frequently
October 20, 2014
Answered

How to add text in .ai file and set position, font, size and colour

  • October 20, 2014
  • 1 reply
  • 1311 views

I want to place multiple lines of of text (individually) into .ai file and set size, font, colour and position for each.

Preferably text should have origin in a single point (rather than be framed)

Hope anyone can help me out.

Thank you in advance.

This topic has been closed for replies.
Correct answer pixxxelschubser

Hi zblj,

this should also works in CS6

var redCMYK = new CMYKColor();

redCMYK.cyan = 0;

redCMYK.magenta = 100;

redCMYK.yellow = 100;

redCMYK.black = 0;

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

aText.top = -150;

aText.left = 50;

aText.textRange.size = 30;

aText.textRange.characterAttributes.fillColor = redCMYK;

aText.textRange.characterAttributes.textFont = textFonts.getByName("MyriadPro-Regular");

aText.contents = "Your Text";   

redraw();

You can find many other textframes, textrange and character properties in the OMV in ExtendScript Toolkit.

Have fun

1 reply

Larry G. Schneider
Community Expert
Community Expert
October 20, 2014

Look in the Scripting Reference for the version you are using. There is a sample script with the information about Creating and modifying text frames.

zblj
zbljAuthor
Participating Frequently
October 20, 2014

I have tried it. In many different ways. It hasn't been long since I started scripting for AI and I really do need help to get me into Adobe's way of thinking.

If you (or anyone else) could show me how to add a text object into .ai file (CS6) I would be very glad.

thank you in advance.

Larry G. Schneider
Community Expert
Community Expert
October 20, 2014

Here's what's in the Scripting Reference

Creating and modifying text frames

// Creates a document with text frames displaying path, area and point

// text, changes the content of each frame then deletes the 2nd frame

// create a new document

var docRef = documents.add();

// create 3 new textFrames (area, line, point)

// Area Text

var rectRef = docRef.pathItems.rectangle(700, 50, 100, 100);

var areaTextRef = docRef.textFrames.areaText(rectRef);

areaTextRef.contents = "TextFrame #1";

areaTextRef.selected = true;

// Line Text

var lineRef = docRef.pathItems.add();

lineRef.setEntirePath( Array(Array(200, 700), Array(300, 550) ) );

var pathTextRef = docRef.textFrames.pathText(lineRef);

pathTextRef.contents = "TextFrame #2";

pathTextRef.selected = true;

// Point Text

var pointTextRef = docRef.textFrames.add();

pointTextRef.contents = "TextFrame #3";

pointTextRef.top = 700;

pointTextRef.left = 400;

pointTextRef.selected = true;

redraw();

// count the TextFrames

var iCount = docRef.textFrames.length;

var sText = "There are " + iCount + " TextFrames.\r"

sText += "Changing contents of each TextFrame.";

// change the content of each

docRef.textFrames[0].contents = "Area TextFrame.";

docRef.textFrames[1].contents = "Path TextFrame.";

docRef.textFrames[2].contents = "Point TextFrame.";

redraw();

docRef.textFrames[1].remove();

redraw();

// count again

var iCount = docRef.textFrames.length;

Your are looking stuff with the pointTextRef.