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

Using the Photoshop API, can I change the tracking value of a specific text character in my textItem

Community Beginner ,
Oct 08, 2020 Oct 08, 2020

Copy link to clipboard

Copied

Is it possible to change specific text properties in PS text using a script? I've gotten the ability to insert text going with a Python wrapper:

doc = psApp.Application.ActiveDocument
layer_scenario_text = doc.ArtLayers["TextLayer"]
text_of_layer = layer_scenario_text.TextItem
text_of_layer.contents = "Text to change"

But is it possible to change say, the tracking value for selected characters with scripting? Looking at the API docs, I've found the textItem.tracking property, but would I be able to have it apply to just ONE part of the string? E.g. the word change in my example would have a tracking of -20 but everything else in the string stays the same?

 

Many thanks!

TOPICS
Actions and scripting , Windows

Views

626

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
Adobe
Community Expert ,
Oct 08, 2020 Oct 08, 2020

Copy link to clipboard

Copied

With DOM code one cannot do everything one can do woth AM code in Photoshop. 

For an example you can see 

https://community.adobe.com/t5/photoshop/change-a-certain-color-of-texts-to-a-new-color/td-p/1146865...

 
But I know of no way to assess the selected parts of a Type Layer except with a work-around that’s convoluted and unreliable … hopefully comeone else can offer more advice. 
 
Did you already download ScriptingListener.plugin? 

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 ,
Oct 08, 2020 Oct 08, 2020

Copy link to clipboard

Copied

Thanks for this, this is actually the first I've heard of the Scripting Listener plugin so I'll give that a look.

Oh boy that's some convuluted code that I'd rather not go down...

Since I'm essentially just making a card game, would I better served with trying to achieve this with something like InDesign or Illustrator? Any pointers on how the code would look like for either, if it's easier?

 

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 ,
Oct 08, 2020 Oct 08, 2020

Copy link to clipboard

Copied

I am afraid text handling is generally more convenient in Indesign and also Illustrator. 

But I am not particularly familiar with either’s DOM. 

 

What is the task you are looking to automate and how often does it arise? 

Could you post a screenshot to illustrate? 

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 ,
Oct 08, 2020 Oct 08, 2020

Copy link to clipboard

Copied

It happens quite often! So the full process that I have at the moment is:

1. A Google spreadsheet contains card text (prompts) and colour.

2. A Python script loops through spreadsheet, generating a JSON out of the data.

3. Script loops through JSON, populating the textItem with prompts, and choosing templates according to the amount of blanks in the string.

 

CAH_fiddles.png

Here's one of my templates. As you can see, the underscores have small spaces between them that can be fixed by highlighting them and setting the tracking value to -20. However, I'd want this to only affect the underscores themselves. I'd thought I could use regex or thing to find them (each blank is 7 underscores so something like (_{7}) would make it fairly easy to find).

 

At the end of this, a PNG is exported and saved for each card. Let me know I can provide more information!

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 ,
Oct 08, 2020 Oct 08, 2020

Copy link to clipboard

Copied

If it is a certain character you want to apply this to then this can be done in Photoshop. 

 

But the design does not look like a good fit for Photoshop and mor appropriate for Indesign (or Illustrator). 

There you could easily create multipage documents and export pdfs, pngs, … for example. 

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 ,
Oct 08, 2020 Oct 08, 2020

Copy link to clipboard

Copied

I'll bear that in mind! I just used PS because it's what I'm familiar with.

For the sake of completeness, since you mentioned that applying things to certain characters can work in PS, could you show me how you'd go about modifying the tracking value for underscores?

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
LEGEND ,
Oct 08, 2020 Oct 08, 2020

Copy link to clipboard

Copied

LATEST

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