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

How to color the elements (texts and shapes)

Enthusiast ,
Mar 14, 2022 Mar 14, 2022

Copy link to clipboard

Copied

Greetings to all and we wish you good luck
I have two questions
- The first question :
I have a group of layers with shapes with colors I want the proportions of colors for these shapes and I have attached an example to clarify what is required

Example 1.jpg

- second question :
I have a text layer with text with lines.. I want to color these lines in a analog way (so that the first line is a color, the second line is a color, the third line is a color, etc..) I have also attached a file for illustration

Example 2.jpg

TOPICS
Actions and scripting , SDK

Views

320

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 , Mar 15, 2022 Mar 15, 2022

 

#target photoshop
 var newColors = ['ff0000', '1200ff', '0f9505', 'c44500'],
     s2t = stringIDToTypeID;
 (r = new ActionReference()).putProperty(s2t('property'), p = s2t('textKey'));
 r.putEnumerated(s2t('layer'), s2t('ordinal'), s2t('targetEnum'));
 if (executeActionGet(r).hasKey(p)) {
     var textKey = executeActionGet(r).getObjectValue(p),
         sList = textKey.getList(s2t('textStyleRange')),
         l = new ActionList(),
         styleSheet = [],
         lines = textKey.getString(s
...

Votes

Translate

Translate
Adobe
Guide ,
Mar 14, 2022 Mar 14, 2022

Copy link to clipboard

Copied

In the first example, I don't see any difference between before and after. Are the "shapes" raster layers or a shape layers?Recently there was a topic with the question of how to change the color of shape layers - Action manager set (shape) layer color. There is an example of a ready-made function in which you only need to substitute the layer indices and color.

 

Where are you planning to get the colors from? Is their list and order fixed or is it generated in some other way?

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
Enthusiast ,
Mar 14, 2022 Mar 14, 2022

Copy link to clipboard

Copied

@jazz-y 

Greetings for your own good
This is a text layer
I want to color the lines in different colors, I will choose it, let it be 4 colors
The first line is red for example.. the second line is blue for example.. the third line is green for example.. and the fourth is orange for example.
These colors will be repeated to complete the lines

Example 2.jpg

 

https://drive.google.com/file/d/1zkTSaFrWQutauYQRiQK0ioKrJUKkvj_i/view?usp=sharing 

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 ,
Mar 15, 2022 Mar 15, 2022

Copy link to clipboard

Copied

LATEST

 

#target photoshop
 var newColors = ['ff0000', '1200ff', '0f9505', 'c44500'],
     s2t = stringIDToTypeID;
 (r = new ActionReference()).putProperty(s2t('property'), p = s2t('textKey'));
 r.putEnumerated(s2t('layer'), s2t('ordinal'), s2t('targetEnum'));
 if (executeActionGet(r).hasKey(p)) {
     var textKey = executeActionGet(r).getObjectValue(p),
         sList = textKey.getList(s2t('textStyleRange')),
         l = new ActionList(),
         styleSheet = [],
         lines = textKey.getString(s2t('textKey')).split('\r');
     for (var i = 0; i < sList.count; i++) {
         styleSheet.push({
             from: sList.getObjectValue(i).getInteger(s2t('from')),
             to: sList.getObjectValue(i).getInteger(s2t('to')),
             style: sList.getObjectValue(i).getObjectValue(s2t('textStyle'))
         })
     };
     var from = 0;
     for (var i = 0; i < lines.length; i++) {
         var to = from + lines[i].length + 1,
             cur = function (s, idx) { for (var i = 0; i < s.length; i++) if (s[i].from <= idx && s[i].to > idx) return s[i].style }(styleSheet, from),
             color = function (h) { var c = new SolidColor; c.rgb.hexValue = h; newColors.push(h); return c }(newColors.shift());
         var d = new ActionDescriptor();
         with (color.rgb) {
             d.putDouble(s2t('red'), red)
             d.putDouble(s2t('green'), green)
             d.putDouble(s2t('blue'), blue)
             cur.putObject(s2t('color'), s2t('RGBColor'), d)
         }
         d = new ActionDescriptor();
         d.putObject(s2t('textStyle'), s2t('textStyle'), cur)
         d.putInteger(s2t('from'), from)
         d.putInteger(s2t('to'), to)
         l.putObject(s2t('textStyleRange'), d)
         from = to
     }
     textKey.putList(s2t('textStyleRange'), l);
     (r = new ActionReference()).putEnumerated(s2t('layer'), s2t('ordinal'), s2t('targetEnum'));
     (d = new ActionDescriptor()).putReference(s2t('target'), r);
     d.putObject(s2t('to'), s2t('textLayer'), textKey);
     executeAction(s2t('set'), d, DialogModes.NO);
 }

 

 

* is a simplified version that assumes that 1 line contains only one style.

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