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

Script to change font only changes first character?

Explorer ,
Jan 12, 2020 Jan 12, 2020

Copy link to clipboard

Copied

Hello, I have a simple script in which the font of a text layer is changed. Certain fonts, however, I have noticed change only the texts first character. So, for example: Test becomes Test, instead of Test

Any idea why this might happen, and a way around it? Thanks!

 

doc.activeLayer.textItem.font = "[Text Postscript Name Here]";

 

 

TOPICS
Actions and scripting , Windows

Views

2.4K

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 1 Correct answer

Guide , Jan 14, 2020 Jan 14, 2020

Now problem is that capitalization = TextCase.ALLCAPS does not really change the case of letters - it changes only the style of their display (essentially it an effect that draws over the text, like any other function from the characters palette 2020-01-15_12-07-12.png). TextItem.contents string does not change.
To really change case of letters, you need to change the case in textItem.contents using .toUpperCase

 

activeDocument.activeLayer.textItem.contents = activeDocument.activeLayer.textItem.contents.toUpperCase()
ac
...

Votes

Translate

Translate
Adobe
Community Expert ,
Jan 12, 2020 Jan 12, 2020

Copy link to clipboard

Copied

Are you sure? try this one.  Was the "Test" in the text layer all the same font to begin with?

 

if (activeDocument.activeLayer.kind==LayerKind.TEXT) { activeDocument.activeLayer.textItem.font = "Tahoma"; }

image.png

 

Even when font are mixed all fonts seem to change I'm on a Windows 10 PC

image.png

JJMack

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 ,
Jan 12, 2020 Jan 12, 2020

Copy link to clipboard

Copied

JJMack,

Font is the same for the entire layer. The same script works correctly with "Tahoma" font (and most others) and changes the entire text.

The issue seems to be with a few fonts downloaded online. 

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 ,
Jan 12, 2020 Jan 12, 2020

Copy link to clipboard

Copied

You should then identify which fonts and where you got them from and which which OS version and Photoshop version you are using..

 

Supply pertinent information for more timely and effective answers. The more information you supply about your issue, the better equipped other community members will be to answer. Consider including the following in your question:

  • Adobe product and version number
  • Operating system and version number
  • The full text of any error message(s)
  • What you were doing when the problem occurred
  • Screenshots of the problem
  • Computer hardware, such as CPU; GPU; the amount of RAM; etc.
JJMack

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 ,
Jan 13, 2020 Jan 13, 2020

Copy link to clipboard

Copied

One such font that fails is "GoodMorning" from DaFont.com (https://www.dafont.com/good-morning-2.font)

I am on Windows 10, 64bit and Photoshop CC 21.0.2

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
Guide ,
Jan 14, 2020 Jan 14, 2020

Copy link to clipboard

Copied

The problem is with the font - it contains glyphs only for CAPITAL letters.

Convert textItem contents string toUpperCase()  before changing font in that case.

 

2020-01-14_22-41-37.png

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 ,
Jan 14, 2020 Jan 14, 2020

Copy link to clipboard

Copied

Whoops, sorry I forgot to mention that I did this as well.

I'm aware the font features only uppercase letters so included the below line of code as well, but still only the first character is changed. 

 

doc.activeLayer.textItem.capitalization = TextCase.ALLCAPS;
doc.activeLayer.textItem.font = "GoodMorning";

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
Guide ,
Jan 14, 2020 Jan 14, 2020

Copy link to clipboard

Copied

Now problem is that capitalization = TextCase.ALLCAPS does not really change the case of letters - it changes only the style of their display (essentially it an effect that draws over the text, like any other function from the characters palette 2020-01-15_12-07-12.png). TextItem.contents string does not change.
To really change case of letters, you need to change the case in textItem.contents using .toUpperCase

 

activeDocument.activeLayer.textItem.contents = activeDocument.activeLayer.textItem.contents.toUpperCase()
activeDocument.activeLayer.textItem.font = "GoodMorning"

 

2020-01-15_09-48-19.png

 

activeDocument.activeLayer.textItem.capitalization = TextCase.ALLCAPS
activeDocument.activeLayer.textItem.font = "GoodMorning"

 

2020-01-15_09-49-20.png

 

activeDocument.activeLayer.textItem.capitalization = TextCase.ALLCAPS
activeDocument.activeLayer.textItem.font = "GoodMorning"
alert (activeDocument.activeLayer.textItem.contents)

 

2020-01-15_09-54-33.png

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
Participant ,
Jun 13, 2023 Jun 13, 2023

Copy link to clipboard

Copied

Hello I want to NOT really change the case, just the style as you mention, which will be the code to do that to the active layer ? I am looking for the other method, thank you.

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
Participant ,
Jun 13, 2023 Jun 13, 2023

Copy link to clipboard

Copied

LATEST

I managed to resolve sorry for botther you, thank you

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