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

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

Community Beginner ,
Aug 12, 2020 Aug 12, 2020

Copy link to clipboard

Copied

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.

TOPICS
Actions and scripting , SDK

Views

776

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

Community Beginner , Aug 23, 2020 Aug 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

Votes

Translate

Translate
Adobe
Community Expert ,
Aug 12, 2020 Aug 12, 2020

Copy link to clipboard

Copied

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.

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
Community Beginner ,
Aug 12, 2020 Aug 12, 2020

Copy link to clipboard

Copied

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:

Screenshot_1.png

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}]

 

 

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

Copy link to clipboard

Copied

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

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

Copy link to clipboard

Copied

Ok, let's talk JS:

3.

var x = 100;
var y = 100;
var pointSample = app.activeDocument.colorSamplers.add([(x - 1),(y - 1)]);
var rgb = [
    pointSample.color.rgb.red,
    pointSample.color.rgb.green,
    pointSample.color.rgb.blue
];

4.

var swatches = readSwatches(); // I assume this method returns an array of objects AS they might be duplicates in the form and the color is already in the preferred form [{name: string, rgb: [red, green, blue]}]
var nameFound = '';
for (var i = 0; i < swatches.length; i++) {
  if (rgb[0] == swatches[i]['rgb'][0] && rgb[1] == swatches[i]['rgb'][1] && rgb[2] == swatches[i]['rgb'][2]) {
    nameFound = swatches[i]['name'];
    break;
  }
}

 5.

presets = readToolPresets(); // Like swatches I have something like {name: string, fontName: string, fontSize: number, fontColor: [red, green, blue], etc...}[]
var selectedPreset = null;
for (var i = 0; i < presets.length; i++) {
  if (nameFound == presets[i]['name']) {
    selectedPreset =  presets[i];
    break;
  }
}

6.

var textLayerRef = document.artLayers.add();
textLayerRef.kind = LayerKind.TEXT;
var textItemRef = document.layers[0].textItem;
textItemRef.kind = TextType.PARAGRAPHTEXT;
textItemRef.font = selectedPreset.fontName;
textItemRef.size = selectedPreset.fontSize;
textItemRef.justification = selectedPreset.fontJustification;
// etc...

 

If you continue with the duplicate problem, I don't know what you want, you are raising issues where there aren't, I don't asked for it, I said to you that there won't be any duplicates, and this code ignore everything when it encounter the first suitable result.

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

Copy link to clipboard

Copied

You need to stop assuming thing and look things up.......

image.png

image.pngimage.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
Community Beginner ,
Aug 12, 2020 Aug 12, 2020

Copy link to clipboard

Copied

And you should stop to imagine things and start reading. I know that readSwatches and readToolPreset don't exist, that's why I commented them and that's what I am asking for, a method to read the swatches and one to read the tool presets. You can search the word "color" in the reference, that's an impressive skill, but tell me, one of the result that you screenshooted does in fact retrieve the swatches? However, none of them contains the word swatch inside the explanation...

Just think about it, I wrote in the first post that I didn't find any clue in the documentation, if I knew which methods I had to use, I wouldn't had opened the thread from the beginning.

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

Copy link to clipboard

Copied

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.

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
Community Expert ,
Aug 12, 2020 Aug 12, 2020

Copy link to clipboard

Copied

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

Capture.jpg

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
Community Beginner ,
Aug 23, 2020 Aug 23, 2020

Copy link to clipboard

Copied

LATEST

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

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