Determining Width and Height of a Text Layer

Find out why the . goes before the /

Moderator: Paul Tuersley

Darkmoon_UK
Posts: 62
Joined: September 5th, 2006, 3:45 am
Location: Chiswick, London, UK
Contact:

In search of a solution, crumbled...

A script writes a text file of the text to be measured, wrap width etc.

It then calls a Photoshop script to render the text in a new document, measure it up using layer bounds and write the result to another text file, which is picked up on by the main script.

It feels dirty and very, very wrong. Adobe, why did you do this to me?
nab
Posts: 203
Joined: November 29th, 2005, 3:00 am
Location: Royan
Contact:

Hello guys,

I bring another tool to determine the text length.

It's based on the same method used by vidpat's TextInfo, thus with the same limitation, but my approach is a little bit different. To avoid weird behaviors with ui updates, and actually in my applications I don't really need sliders, I just need to know the precise length of my text and use this value later in my script for something else (adjust keyframe values,...).

The plug-in determines the width of the visible part of a text layer and writes the value to a txt file. Then it's easy with a script to apply this effect to any text layer, retrieve/read the value from the txt file, use it for your needs and remove the file. Voilà.

It's definitely "script-oriented".

The path of the txt file is hardcoded in the plug-in, "c:\textLength.txt", I don't know the path for the Mac sytem, but if a mac user is interested in and can send me the appropriate 'path syntax' for Mac, I will add it in the plug-in.

I join a sample jsx script that applies this effect and schedules a task to get the width from the txt file (it's commented).

This is my first plug-in so everyone is allowed to throw tomatoes :D

(.aex -> in the AE plug-in folder, jsx -> no matter)
http://www.nabscripts.com/Forum/Scripts ... cripts.zip
bradshaw1965
Posts: 98
Joined: March 14th, 2006, 2:16 pm
Location: Atlanta, GA
Contact:

Hey nab,

Care to share the source and I'll compile a Mac version?

Dale
Dale Bradshaw
Technology Director | Primal Screen
creative-workflow-hacks.com
Atlanta, GA
Darkmoon_UK
Posts: 62
Joined: September 5th, 2006, 3:45 am
Location: Chiswick, London, UK
Contact:

Nice solution, nab!

My photoshop method was messy and sloo-o-oow; and probably would only have worked properly had I delved into the world of Adobe Bridge, which I don't have the time to learn mid-project. I am currently using the method of coding an 'average characters per line' solution to determining the height. Actually despite being unelegant it's produced surprisingly consistent results.

I will definitely give your script a go though, far better method, thanks again for sharing.
User avatar
lloydalvarez
Enhancement master
Posts: 460
Joined: June 17th, 2004, 9:27 am
Location: New York City, NY
Contact:

nab wrote: The path of the txt file is hardcoded in the plug-in, "c:\textLength.txt", I don't know the path for the Mac sytem, but if a mac user is interested in and can send me the appropriate 'path syntax' for Mac, I will add it in the plug-in.
Hey Nab,

Nice Plugin! Thanks! For my BG Renderer script, i write my temp file to the user's pref's directory:

var prefsPath = "~/Library/Preferences";

This is a directory where you won't run in any permission problems and the user is not likely to mind a random file.

-Lloyd
nab
Posts: 203
Joined: November 29th, 2005, 3:00 am
Location: Royan
Contact:

Thanks guys for your feedback

I've modified the plug-in a bit to export the height of the text layer as well (the plug is now called "TextDimensions.aex") .

I have few new ideas to improve the plug-in but it takes a lot a time -for a beginner- to understand how functions work and how they can be manipulate...

Two main problems:
- doesn't support 3d text layer (ae gives me the whole comp size)
- doesn't support off-screen layer (i've an idea to tackle this pb but not yet implemented)

Dale, I will send the source codes and some notes to dale(at)creative-workflow-hacks(dot)com (give me two or three days..).
bradshaw1965
Posts: 98
Joined: March 14th, 2006, 2:16 pm
Location: Atlanta, GA
Contact:

nab wrote:Dale, I will send the source codes and some notes to dale(at)creative-workflow-hacks(dot)com (give me two or three days..).
sounds great, I appreciate your efforts.

Dale
Dale Bradshaw
Technology Director | Primal Screen
creative-workflow-hacks.com
Atlanta, GA
nab
Posts: 203
Joined: November 29th, 2005, 3:00 am
Location: Royan
Contact:

An easy way to obtain the correct text length when the text is not visible (or partially), is -through scripting- to duplicate the original text layer, set appropriately the anchor point and position (something like [0,0] and [10,compH/2] should be ok), then apply the effect/plugin to this dummy layer to retrieve the text length and finally remove this layer.
Devastator
Posts: 5
Joined: January 30th, 2007, 3:21 am

I seem to be having problems with all 3 scripts / plugins.

With nab's AEX file, I get "Adobe Effects error: plug-in "(path)\TextLength.aex" could not be loaded (14001) (48 :: 46)".

When I try using the JSX file, I get "Unable to execute script at line 16. After Effects error: invalid filter".

Lastly, when I tried using TextInfo.aex, I did receive the right height and width 'once'. After that, when I enabled the effect (CC Light Burst) and moved the text as a test, the height and width were that of the composition. Ever since then, I've been getting 0 for the height and width, even if I close AFX and try again.
vidpat
Posts: 86
Joined: October 21st, 2004, 12:36 am
Location: Phoenix, AZ
Contact:

Yes, TextInfo probably will return the height and width of the entire comp when you apply an effect that renders to the entire comp area if TextInfo comes later in the effects stack. Possible workarounds: place TextInfo first in the effects stack, apply the other effect(s) to an adjustment layer, use the text as a track matte (depends upon the effect), or precomp-the text with TextInfo.

TextInfo is not to be considered a perfect usable solution.
Devastator
Posts: 5
Joined: January 30th, 2007, 3:21 am

Thanks for that info. I guess I wasn't thinking too clearly about the effects stack, as that did the trick. I've read the reasoning as to why it's not considered a perfect usable solution, but for me, it's exactly what I was looking for.
vranan
Posts: 13
Joined: February 8th, 2005, 9:53 am
Contact:

Did anybody manage to convert the textlength.aex for a mac?
If yes would it be possible to post it on this forum?

Thank you.
Nino
yuppster
Posts: 16
Joined: March 3rd, 2006, 4:01 pm

I'd also be very interested in something like this was available for Mac? Any plans?
nab
Posts: 203
Joined: November 29th, 2005, 3:00 am
Location: Royan
Contact:

I can't help on the mac side but I've sent my source code to Dale.
nab
Posts: 203
Joined: November 29th, 2005, 3:00 am
Location: Royan
Contact:

My compiler settings were not properly adjusted and the 'TextLength' plugin was working fine on my pc only !

So I recompiled with 'good settings' and now this should work for any windows user.

Here is the new link (there is also a sample .jsx in the zip to show how to retrieve the text dimensions from the file created by the plug-in) :

http://www.nabscripts.com/Forum/Plugins ... nsions.zip

edit: i've updated the jsx because the script was using the 'textDimensions.txt' file instead of 'TextDimensions.txt'
Post Reply