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

If it is possible to retrive the information you want to know you would need to use Action Manager Code there is no reference to swatch at all in  Photoshop Scripting DOM. 

 

You also seem to be imagining that Photoshop is associating a swatch name with a fill layer or shape layer or that a RGB Color will have a unique swatch name somewhere.   My imagination tells me that Photoshop does not associated a swatch name to a shape layer anywhere.   A color can be picked  from Photoshop color pickers and have no swatch name association.

 

I have been using  Photoshop for over 20 years.  Though I'm not a Photoshop Script expert I have hack many scripts over the years I do have some knowledge and a many years of observing Photoshop working.   Adobe does not make Photoshop source code public and Adobe documentation does not document how each function is implemented.  Documentation is not the best and No one know all of Photoshop.

 

I believe the only place there are unique names is in a documents Path palette.  In a document's Path Palette names seem to be unique but the paths can be renamed.  Relying on Names in an Automated Photoshop process other then in the Paths Palette is a problem waiting to happen IMO.

 

I think you would be better off  documenting the color space the RGB hex code layer opacity blending  etc then  trying to document swatch names the can be changes at any time.

 

 

By the way you can export a shape layer as a *.svg vector file.  If you open that  *.svg file in a text editor you may like what you see.


The Path may be huge though but look at the other data in the svg file......

JJMack