Skip to main content
Inspiring
August 12, 2020
Answered

[jsx] read the content of exported swatch and tool preset

  • August 12, 2020
  • 2 replies
  • 1481 views

Hi, I am new to ExtendScript but I develop in Javascript from years. I am trying to make a script for PS 2020 that do these steps:

 

1. open psd file

2. look at layers in a group

    - those layers are a convex shape for each layer of a certain color

    - the color is a specific one from a defined swatch and has a specific name

3. get the color from the center of the shape

4. read the exported swatch to identify the name used

5. read the exported tool preset to identify the font properties to use searching by name

6. write some text from a file in a text layer of the dimensions of the shape

    - the text has a certain font, dimension and style from a tool preset with the same name of the swatch used

7. save and close

 

I have trouble to do the steps 4 and 5 as I don't know how to do them and I can't find it on the documentations. If it can't be done from an external file it's not a problem getting it from PS. Does anyone know how to code it? Thank you.

This topic has been closed for replies.
Correct answer Ripper346

I came up with a solution alone. For anyone searching for this, you can take a look to my answer for the same question here https://graphicdesign.stackexchange.com/a/140443/155610

2 replies

Ripper346AuthorCorrect answer
Inspiring
August 23, 2020

I came up with a solution alone. For anyone searching for this, you can take a look to my answer for the same question here https://graphicdesign.stackexchange.com/a/140443/155610

JJMack
Community Expert
Community Expert
August 12, 2020

I do not think what you want to do will be possible. A shape layer in Photoshop is a Fill layer. Its fill can be empty, a solid color, a pattern or a gradient. If it is a solid color you may be able to retrieve the color rgb numbers or perhaps name and index number for the fill an index to a swatch, a pattern, a gradient.  I would not think  that name or content need be unique that presets can be loaded more than once. That names in different groups can duplicate names in other  groups and name in a group may be duplicated in the group and have the same or different settings.  Names may also be renamed. Using Names in Photoshop animations often is not a good idea. Which is the correct Swatch 2.  If you add things to Photoshop do you know all nanes added  will not duplicate with existing names and that no additional name will ever be added.

JJMack
Ripper346Author
Inspiring
August 12, 2020

I do not think what you want to do will be possible. A shape layer in Photoshop is a Fill layer. Its fill can be empty, a solid color, a pattern or a gradient. If it is a solid color you may be able to retrieve the color rgb numbers or perhaps name and index number for the fill an index to a swatch, a pattern, a gradient. [...] If you add things to Photoshop do you know all nanes added  will not duplicate with existing names and that no additional name will ever be added.

That's not the problem I asked about, but my sample layers are like a oval, a rectangle or a fill of solid color corresponding to a swatch preset I can simply look at the center pixels to have their precise color.

 

I would not think that name or content need be unique that presets can be loaded more than once. That names in different groups can duplicate names in other groups and name in a group may be duplicated in the group and have the same or different settings. Names may also be renamed.

Duplicates or renaming it isn't a problem either. The script assumes that they are unique, if they aren't it is a problem of the end user to not to be.

 

Using Names in Photoshop animations often is not a good idea. Which is the correct Swatch 2.

These periods are obscure to me. Animations?! Swatch 2?!

 

Maybe I explained my problem badly even if I wrote the pseudo code. Take this example:

I have two swatches, one red named Myriad and one blue named Arial.

I have also two text presets, one named Myriad that write text in Myriad Regular 15pt black and one named Arial that write text in Arial Regular simulated Italic all caps 15pt black.

Now let's say that I export my swatches of Brochure folder inside broshure.aco and the presets inside brochuse.tpl.

 

Then I make a new psd file, I place inside the group of layers Group 1 one layer containing a red rectangular and another with some blue brushing.

Now open a fancy editor and start writing code for photoshop. I arrive to get a set of layers, one red and one blue. So, my question, this topic, revolves around (and nothing more) how I can open with extendScript the files brochure.aco and brochuse.tpl to have the settings inside? And if it is impossible, is it possible to get these information from photoshop otherwise?

All I need is to get in the end something like:

 

swatches = [{name: 'Myriad', color: '#ff002a'}, {name: 'Arial', color: '#0004ff'}]
textPresets = [{name: 'Myriad', font: 'Myriad Regular', size: 15}, {name: 'Arial', font: 'Arial Regular', size: 15}]

 

 

JJMack
Community Expert
Community Expert
August 12, 2020

IMO if your script assumes name are unique. I feel you have a problem they may not be  your script does not verify they are unique.  Your the user that authored the script. Does Photoshop even record name of swatches you select in the Shape tools option ba in thet layer?  Photoshop may simply set the RGB hex values into the shape fill layers.  

 

You havE a problem with step 4 and 5.   I have a problem with 3 and 4 how do they releate ?

 

3. get the color from the center of the shape

4. read the exported swatch to identify the name used

JJMack