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

Illustrator Script - TextFrame size and positioning

Explorer ,
Mar 31, 2021 Mar 31, 2021

Copy link to clipboard

Copied

Greetings,

I'm trying to wrap my head around Illustrator Scripts. The company I work for has a series of documents that I'm designing that contain images and text. They all have the same template, which I've put together in Illustrator, but different content. I'm using Illustrator Dynamic Variables to import the text into the textFrames that I have put on screen, which works great, except that some text in Paragraph 1 falls shorter than the TextFrame it is in, while the text under it is longer and doesn't fit within it's Text Frame.

 

What I'm trying to do, is find a means to resize the top TextFrame to fit it's contents, and use it's position and height as a basis to move the second paragraph up the page and resize it's TextFrame to accomodate the text within it.

So far I've read a lot about the various properties of TextFrames and have learned that I can reposition the text frame using something like this:

sourceDoc.textFrames[0].translate(0,100)
 
I've also identified that the frames I need to move are the following:
sourceDoc.textFrames[3].contents // First textArea
sourceDoc.textFrames[1].contents // Second textArea

Does anyone know if what I'm asking is possible, and 
does anyone happen to have a script that either does this or something similar that I could use as reference?
TOPICS
Scripting

Views

2.9K

Translate

Translate

Report

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 2 Correct answers

Community Expert , Mar 31, 2021 Mar 31, 2021

 

function stackTwoTextFrames(frame1, frame2)
{
	const SPACING = 15;
	frame2.left = frame1.left;
	frame2.top = frame1.top - frame1.height - SPACING;
}
stackTwoTextFrames(app.activeDocument.textFrames[0],app.activeDocument.textFrames[1]);

 

 

link to function on github 

 

Votes

Translate

Translate
Explorer , Mar 31, 2021 Mar 31, 2021

After a bit of searching, I managed to find this:
https://community.adobe.com/t5/illustrator/fit-frame-to-text-free-script/td-p/8715225

It appears to do what I need it to. The for loop wasn't working initially, but when I passed in the actual objects I had figured out how to target earlier, it worked perfectly. 

Votes

Translate

Translate
Adobe
Community Expert ,
Mar 31, 2021 Mar 31, 2021

Copy link to clipboard

Copied

 

function stackTwoTextFrames(frame1, frame2)
{
	const SPACING = 15;
	frame2.left = frame1.left;
	frame2.top = frame1.top - frame1.height - SPACING;
}
stackTwoTextFrames(app.activeDocument.textFrames[0],app.activeDocument.textFrames[1]);

 

 

link to function on github 

 

Votes

Translate

Translate

Report

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 ,
Mar 31, 2021 Mar 31, 2021

Copy link to clipboard

Copied

Thanks for getting back to me!
I looked over that script, and I can see how it works. It's pretty simple compared to the path I was travelling down.

Now, the only other question I'm struggling is the part about resizing a TextFrame to fit it's contents. 

Let's say that a TextFrame is 100px tall, but it's contents only total 50px in height. That means there's 50px of empty space at the bottom of the frame that isn't being used. Another example, let's say that the text occupies about 150px worth of height but because the TextFrame is only 100px tall, the text gets cut off mid sentence and 1/3rd of the total text does not appear on screen.

Is there a way to resize the TextField to fit the content within it?

Votes

Translate

Translate

Report

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
Community Expert ,
Mar 31, 2021 Mar 31, 2021

Copy link to clipboard

Copied

i just re-read your post and realized that i misunderstood it.

 

I'm not sure at this moment exactly how to resize the textframe to fit the text.. but once we figure that part out, the other function i posted will come in useful.

Votes

Translate

Translate

Report

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 ,
Mar 31, 2021 Mar 31, 2021

Copy link to clipboard

Copied

Hah, I was just writing back regarding that aspect of it. You're right in that what you provided will work perfectly, once I figure that other part out. Thank you for your help. I deeply appreciate it.

Votes

Translate

Translate

Report

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 ,
Mar 31, 2021 Mar 31, 2021

Copy link to clipboard

Copied

After a bit of searching, I managed to find this:
https://community.adobe.com/t5/illustrator/fit-frame-to-text-free-script/td-p/8715225

It appears to do what I need it to. The for loop wasn't working initially, but when I passed in the actual objects I had figured out how to target earlier, it worked perfectly. 

Votes

Translate

Translate

Report

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
Community Expert ,
Mar 31, 2021 Mar 31, 2021

Copy link to clipboard

Copied

Hi @GBoyd 

with a newer version of Illustrator I would "think a little around the corner"

 

Try the following (before using the snippet from @Disposition_Dev)

var aDoc = app.activeDocument;
var aTF = aDoc.textFrames[0];
aTF.convertAreaObjectToPointObject();
aTF.convertPointObjectToAreaObject();

 

This should set the height of textFrame[0] to the minimum required height.

 

If that works for you

have fun

😉

Votes

Translate

Translate

Report

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 ,
Mar 31, 2021 Mar 31, 2021

Copy link to clipboard

Copied

Hi pixxxelschubser,

That looks like a fine solution, except that I am encounting one issue with it. If my TextFrame is smaller than the amount of text in it your solution seems to disregard all of the text that is being cut off, rather than expanding the TextFrame to fit the text that is caught outside of the frame. However, what you have there works great if the amount of text is smaller than the TextFrame.

 

Unforunately, The amount of text I'm importing into my document is unknown. Sometimes it'll be very little, other times it'll be a lot of text. So I need to make sure it works in all situations.

Thanks again for showing me that, it'll help me learn more about Scripting for Illustrator.

Votes

Translate

Translate

Report

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
Community Expert ,
Apr 03, 2021 Apr 03, 2021

Copy link to clipboard

Copied

@pixxxelschubser 

I tried this approach when i was testing things before i posted here.. and i was able to convert the frame to point text thus trimming the extra space from the bottom of the textFrame.. However, i was subsequently unable to convert the frame back to areaText..? There was no error, but the textFrame remained point text until i adjusted it manually in the UI.

 

Any thoughts?

 

Votes

Translate

Translate

Report

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
Community Expert ,
Apr 03, 2021 Apr 03, 2021

Copy link to clipboard

Copied

quote

var aDoc = app.activeDocument;
var aTF = aDoc.textFrames[0];
aTF.convertAreaObjectToPointObject();
aTF.convertPointObjectToAreaObject();

 

This should set the height of textFrame[0] to the minimum required height …

 

By @pixxxelschubser

 

@Disposition_Dev 

Hmmh …

Works for me as expected. With one exception: as @GBoyd  already wrote - if you have overset text then the overset text will actually be cut off / removed.

 

 

 

Votes

Translate

Translate

Report

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
Community Expert ,
Apr 03, 2021 Apr 03, 2021

Copy link to clipboard

Copied

Weird.. I'll keep trying I guess...

Votes

Translate

Translate

Report

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
Community Expert ,
Apr 03, 2021 Apr 03, 2021

Copy link to clipboard

Copied

As a sidenote:

I tried it with Illustrator v25.2 under Windows 10

Votes

Translate

Translate

Report

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
Community Expert ,
Apr 03, 2021 Apr 03, 2021

Copy link to clipboard

Copied

That could be important. I tried on 24.3 on Mac.

 

I have v25.x installed as well, I'll try it there.

 

But if it only works on new versions, I consider it to not work at all. For a myriad of reasons, we wait a long time to adopt new illustrator versions at my work.. They always cause more problems with our work flow than they solve. And virtually every freelance client I've had has been between cs6 and cc2020. 

Votes

Translate

Translate

Report

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
Community Expert ,
Apr 03, 2021 Apr 03, 2021

Copy link to clipboard

Copied

I tried it now with Illustrator 19.2.1 (CC2015)

It works fine there too.

Votes

Translate

Translate

Report

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
Community Beginner ,
Feb 09, 2022 Feb 09, 2022

Copy link to clipboard

Copied

LATEST

no need to extra scripts or tricks. Just go with this link.

This saves me from big problem.

https://millo.co/overlooked-illustrator-feature-first-now-saves-time-headaches

Votes

Translate

Translate

Report

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