Copy link to clipboard
Copied
I'm trying to create a text box with a script, so that the type area has a max width, and contents will auto line beak to fill the space. The plan is for a storyboard template generating tool, putting textboxes below each frame.
This script will create a text object, but setting the width will squsih/stretch the text content to the set width, not create a textbox at that width I can then fill.
I'm trying to get this to work like you simply clicked and draged out a type container, giving it a set width.
var textFrame = app.activeDocument.textFrames.add();
textFrame.kind = TextType.AREATEXT;
// Set the text contents
textFrame.contents = "Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.";
// Set the maximum width
textFrame.width = 200;
textFrame.top = -100;
textFrame.left = 100;
There's 2 ways to go about this.
1) you create a rectangle path at your desired position and size and then turn that path into an area text frame
var Rect = app.activeDocument.pathItems.rectangle(Y,X,Width,Height)
/* you will have to change the Y X width Height values to meet your needs. usually the Y value is a negative based number so from top left of artboard -Y will move the object to the bottom of the artboard. X works as regular left is 0 right is positive number.*/
var AreaText = app.activ
...
Copy link to clipboard
Copied
There's 2 ways to go about this.
1) you create a rectangle path at your desired position and size and then turn that path into an area text frame
var Rect = app.activeDocument.pathItems.rectangle(Y,X,Width,Height)
/* you will have to change the Y X width Height values to meet your needs. usually the Y value is a negative based number so from top left of artboard -Y will move the object to the bottom of the artboard. X works as regular left is 0 right is positive number.*/
var AreaText = app.activeDocument.textFrames.areaText(Rect)
AreaFrame.contents = "Test Box"
2) create your area text frame and then you alter the textpath of the frame to alter the dimensions without skewing the text
var AreaFrame = app.activeDocument.textFrames[0]
/* target your area text frame and then set the values of each coordinate left/top/height/width*/
AreaFrame.textPath.left = 10 /* x coord */
AreaFrame.textPath.top = -20 /* y coord usually negative based */
AreaFrame.textPath.height = 50;
AreaFrame.textPath.width = 100;
Copy link to clipboard
Copied
Thank you, that option using a Rect works for me,