Copy link to clipboard
Copied
Hi All,
Im attempting to write a script that can automate the process of changing a RGB colour of a layerEffect - such as stroke, dropshadow or coloroverlay.
Im aware it is ActionManager code that can accomplish this. Has anyone got any ideas of how to "modify" the existing set of layerEffects and target only the correct effect, as Ive only been able to get so far as updating the new color, but it deletes all the other existing layerEffects.
If copying the whole layerEffects object is required, then modifying the correct component and then pasting it back onto that layer is required, any assistance or ideas of how to accomplish this would be much appreciated.
Thanks in advance.
@Symo470 I don’t know what’s the matter, but the restriction on sending private messages is regularly triggered for me.
You asked in a private message about replacing colors in gradients. With a gradient, the principle is the same, just a little more steps when assembling an object. First, we get each element of the object and save it to a variable, then we set new colors and put everything in reverse order.
The only thing is that the gradient object is more complicated than the fill, so a simple
...Copy link to clipboard
Copied
Copy link to clipboard
Copied
I think Ive identified what you've stated.
I run my script several times using getLaterStyle and setLayerStyle and it can produce different results each time.
Where do we start to get this updated for PS 2020 and beyond?
Copy link to clipboard
Copied
@Symo470 I don’t know what’s the matter, but the restriction on sending private messages is regularly triggered for me.
You asked in a private message about replacing colors in gradients. With a gradient, the principle is the same, just a little more steps when assembling an object. First, we get each element of the object and save it to a variable, then we set new colors and put everything in reverse order.
The only thing is that the gradient object is more complicated than the fill, so a simple color change is not enough here: you must definitely compare the number of colors in the gradient and the arguments passed to the function (in the example, replace colors in any three-color gradient) in order to preserve the integrity of the object. And the multi-effect is more difficult to process (the example simply ignores this situation, although you can, for example, take only the first gradient from the list and replace the colors in it).
changeFill([255, 0, 0], [0, 255, 0], [0, 0, 255]); // [R, G, B] values
function changeFill() {
s2t = stringIDToTypeID;
(r = new ActionReference()).putProperty(s2t('property'), p = s2t('layerEffects'));
r.putEnumerated(s2t('layer'), s2t('ordinal'), s2t('targetEnum'));
if (executeActionGet(r).hasKey(p)) var fx = executeActionGet(r).getObjectValue(p);
if (fx && fx.hasKey(p = s2t('gradientFill'))) {
var gradientFill = fx.getObjectValue(p),
gradient = gradientFill.getObjectValue(s2t('gradient')),
colors = gradient.getList(s2t('colors'));
if (arguments.length == colors.count) {
var newColors = new ActionList();
for (var i = 0; i < colors.count; i++) {
var currentColor = colors.getObjectValue(i);
(d = new ActionDescriptor()).putDouble(s2t('red'), arguments[i][0]);
d.putDouble(s2t('green'), arguments[i][1]);
d.putDouble(s2t('blue'), arguments[i][2]);
currentColor.putObject(s2t('color'), s2t('RGBColor'), d)
newColors.putObject(s2t('colorStop'), currentColor)
}
gradient.putList(s2t('colors'), newColors)
gradientFill.putObject(s2t('gradient'), s2t('gradientClassEvent'), gradient);
fx.putObject(s2t('gradientFill'), s2t('gradientFill'), gradientFill);
(d = new ActionDescriptor()).putReference(s2t('null'), r);
d.putObject(s2t('to'), s2t('layerEffects'), fx);
executeAction(s2t('set'), d, DialogModes.NO);
}
}
}
Ask questions on the public platform of the forum, put likes, mark the right solutions to help other users find answers on similar questions - this is the best way.
Copy link to clipboard
Copied
@Symo470 – Please mark one or multiple answers as correct so that others with the same/similar question know that an answer was found.