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

Creating a Non-Stretching Text Box with Fixed Width in Illustrator Scripting

Explorer ,
Oct 24, 2024 Oct 24, 2024

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;

 

TOPICS
Scripting , Tools , Type
253
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 1 Correct answer

Participant , Oct 24, 2024 Oct 24, 2024

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
...
Translate
Adobe
Participant ,
Oct 24, 2024 Oct 24, 2024

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;

 

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 ,
Oct 24, 2024 Oct 24, 2024
LATEST

Thank you, that option using a Rect works for me,

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