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

Script to center text vertically in adobe illustrator?

Community Beginner ,
Feb 02, 2018 Feb 02, 2018

Does anyone know of a script to do this?  I imagine the script will have to take the height of the text-box and divide it by two.  However, the size of the text will probably have to be taken into consideration as well.

vertical_alignment.jpg

4.5K
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
Adobe
Community Expert ,
Feb 02, 2018 Feb 02, 2018

The script would have to calculate something such as a baseline shift, and you would need to let us know what you want to do about ascenders and descender.

Might be better to post here, or I can move your post for you

Illustrator Scripting

There are ways to do this without scripting, of which will add a separate reply.

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
Community Beginner ,
Feb 02, 2018 Feb 02, 2018

I have a hard time believing there isn't a script that auto-adjusts the baseline shift in the Character menu.

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
Community Expert ,
Feb 03, 2018 Feb 03, 2018

matthews63743827  schrieb

I have a hard time believing there isn't a script that auto-adjusts the baseline shift in the Character menu.

I have a hard time believe …

… that you completely ignored the questions and advices of MikeGondek​

Please see that screenshot. In your opinion - where (or what) is the best alignment???

alignment_text.png

What kind of alignment do you prefer?

Do you have some examples with a detailed explanation (or at the best an: example.ai) for us?

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
Community Expert ,
Feb 03, 2018 Feb 03, 2018

Please no insults.

And then: again read my contribution, think meticulously and then answer.

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
Community Expert ,
Feb 03, 2018 Feb 03, 2018
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
LEGEND ,
Feb 04, 2018 Feb 04, 2018
...a vertical align script is likely possible, and probably fairly simple, especially since InDesign has a vertical align option.

Illustrator and InDesign use entirely different text engines. Illustrator (lamely) shares the one in Photoshop, not the one in InDesign.

I wonder how they made that work?  Oh yes! Code.

Just because two programs (ex:, InDesign and Illustrator) can be scripted does not mean that the same things can be done in them with a script. What can be done via scripting in either program is entirely dependent upon what objects, methods, and properties are defined in the scripting API for that program.

Vertically-centering text is a built-in feature of an InDesign textFrame object. So (although I haven't checked) the textFrame object in InDesign's scripting API probably has a property for vertical centering whereas Illustrator's API does not. So in InD scripting, vertically centering text probably just involves setting a textFrame's property. But doing it in AI scripting, would require devising a considerably more tedious and elaborate workaround for the absence of that property, which is why people are trying to get you to understand that "centering" text vertically is an ambiguous requirement because "height" of text  is typeface-specific.

The problem is very much the same as the common complaint that software text is not actually scaled to the visible "height" of the characters. People in the sign trade, for example, are often required by customers (who don't understand typography) to create text at a specific measured "height."  In order to state that problem in terms of "code," you have to exactly specify what "height" means to you. (The height of an italic glyph's flourish? The X height? The Cap Height?)

Years ago, I wrote an Illustrator script which "sets" type to what most users with that complaint usually want: the CapHeight. It works, but the "behind-the-scene" workaround involved was rather ridiculous: It obtained the size attribute from a character in the selected textFrame, created a temporary textFrame object at the page origin, set its content to a single X character, converted it to paths in order to obtain the height of the path, deleted the path, and then used that height as a scaling factor for the text size of the selected textFrame.

So yeah, someone could write an AI script to do what you want using some similarly silly workaround, if you specifically detail your expectations. But I wouldn't bother doing it because I quit expending time and energy on scripts for Adobe applications the day Adobe decided I had to rent its software, and because  there is a commonly used workaround for vertically centering text in a box anyway:

  1. Create a PathType object.
  2. In the Appearance Palette, give it an additional Fill.
  3. Position the second Fill below the Characters listing.
  4. Apply the Convert To Shape Effect to the second Fill and set its Extra Space value as desired.
  5. Save the whole construct somewhere (as a Symbol, for example) so it can be re-used elsewhere.

JET

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
Community Expert ,
Feb 04, 2018 Feb 04, 2018
LATEST

Hi JETalmage​,

well spoken.

JETalmage wrote:

… Years ago, I wrote an Illustrator script which "sets" type to what most users with that complaint usually want: the CapHeight. It works …

Funny, I did the same, but for Photoshop only (years ago).

JETalmage wrote:

… workaround for vertically centering text in a box anyway:

  1. Create a PathType object.
  2. In the Appearance Palette, give it an additional Fill.
  3. Position the second Fill below the Characters listing.
  4. Apply the Convert To Shape Effect to the second Fill and set its Extra Space value as desired.
  5. Save the whole construct somewhere (as a Symbol, for example) so it can be re-used elsewhere.

…

Exactly.

This is, how the yellow boxes in my post #5 was created.

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
Community Expert ,
Feb 02, 2018 Feb 02, 2018

If you goal is to get the type in the center of the text box, that is not possibly in Illustraro as in InDesign.

You can have the align palette to do this, but you need to do 2 things

  1. Add an effect >>Path >>  outline Object to your tyep element
  2. Turn on use preview bounds

Screen Shot 2018-02-02 at 9.19.05 AM.png

The reason the align palette does not by default center text, is that it is centering upon the font (including the space above and below the ascenders and descenders, coded into the font. 

Not sure if this helps you, but please clarify or provide an example with more detail of what your end result you are looking to do.

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
Community Expert ,
Feb 02, 2018 Feb 02, 2018

Or you may be content with double clicking here

Screen Shot 2018-02-02 at 9.26.17 AM.png

to trim excess unused height from your text container. I added a descender so you can see how  important this is to consider.

Screen Shot 2018-02-02 at 9.28.22 AM.png

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