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

Modify a “LayerEffects” object

Community Beginner ,
Jul 11, 2021 Jul 11, 2021

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.

TOPICS
Actions and scripting

Views

1.1K

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 , Jul 23, 2021 Jul 23, 2021

@Symo470 I don’t know what’s the matter, but the restriction on sending private messages is regularly triggered for me. 

2021-07-23_22-08-27.png

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

...

Votes

Translate

Translate
Adobe
Community Expert ,
Jul 11, 2021 Jul 11, 2021

Copy link to clipboard

Copied

You need help only a few here can provide  r-bin, supermerlin, jazz-y, Kukurykus, participate here often and have the knowledge  required to code the Action manager code to retrievt a layer's current layer styles effects if it is possible.,

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 ,
Jul 11, 2021 Jul 11, 2021

Copy link to clipboard

Copied

Thanks... ive noticed these names on the threads. I hope to hear from one of the experts! Cheers.

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 ,
Jul 11, 2021 Jul 11, 2021

Copy link to clipboard

Copied

I too am curious to see what the "usual suspects" come up with, I only hack at AM code... For example, if the selected layer has a Color Overlay effect applied, the following code will change only the fill RGB values.

 

I recorded the original code using ScriptListener and then used the Clean SL script to simplify it somewhat, then tried to work out which bits of code were superflurous for the task of changing the fill colour and remove them without breaking anything. You could of course add a check to see if the selected layer has a Color Overlay effect applied and or do any number of other things. Again, this is just a hack, I'm sure that those familiar with AM code will achieve the same with one third of the code!

 

changeFill(255, 0, 0); // R, G, B values

function changeFill(red, green, blue) {
	var s2t = function (s) {
		return app.stringIDToTypeID(s);
	};
	var descriptor = new ActionDescriptor();
	var descriptor2 = new ActionDescriptor();
	var descriptor3 = new ActionDescriptor();
	var descriptor4 = new ActionDescriptor();
	var reference = new ActionReference();
	reference.putProperty( s2t( "property" ), s2t( "layerEffects" ));
	reference.putEnumerated( s2t( "layer" ), s2t( "ordinal" ), s2t( "targetEnum" ));
	descriptor.putReference( s2t( "null" ), reference );
	descriptor4.putDouble( s2t( "red" ), red );
	descriptor4.putDouble( s2t( "grain" ), green );
	descriptor4.putDouble( s2t( "blue" ), blue );
	descriptor3.putObject( s2t( "color" ), s2t( "RGBColor" ), descriptor4 );
	descriptor2.putObject( s2t( "solidFill" ), s2t( "solidFill" ), descriptor3 );
	descriptor.putObject( s2t( "to" ), s2t( "layerEffects" ), descriptor2 );
	executeAction( s2t( "set" ), descriptor, DialogModes.NO );
}

 

 

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 ,
Jul 11, 2021 Jul 11, 2021

Copy link to clipboard

Copied

I have made my way to the same position, but the problem is that the code replaces ALL the layerEffects of that layer.

So, for example, if im looking to change ONLY the color of a Stroke (frameFX) layerEffect, but keep the thickness/size or opacity the same - At presente, if I use Script Listener code and remove those items I dont want to change , it will update the layer with default (i assume) 

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 ,
Jul 11, 2021 Jul 11, 2021

Copy link to clipboard

Copied

That is where the people that know, rather than hack at AM code come into play! :]

 

I will be interested to see the answers...

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 ,
Jul 22, 2021 Jul 22, 2021

Copy link to clipboard

Copied

 

#target photoshop

changeFill(255, 0, 0); // R, G, B values
function changeFill(red, green, blue) {
    s2t = stringIDToTypeID;

    (r = new ActionReference()).putProperty(s2t("property"), p = s2t("layerEffects"));
    r.putEnumerated(s2t("layer"), s2t("ordinal"), s2t("targetEnum"));
    var fx = executeActionGet(r).hasKey(p) ? executeActionGet(r).getObjectValue(p) : new ActionDescriptor(),
        currentFill = fx.hasKey(p = s2t("solidFill")) ? fx.getObjectValue(p) : new ActionDescriptor();
    if (fx.hasKey(p = s2t("solidFillMulti"))) fx.erase(p);

    (d = new ActionDescriptor()).putDouble(s2t("red"), red);
    d.putDouble(s2t("green"), green);
    d.putDouble(s2t("blue"), blue);
    currentFill.putObject(s2t("color"), s2t("RGBColor"), d);
    fx.putObject(s2t("solidFill"), s2t("solidFill"), currentFill);

    (r = new ActionReference()).putProperty(s2t("property"), s2t("layerEffects"));
    r.putEnumerated(s2t("layer"), s2t("ordinal"), s2t("targetEnum"));
    (d = new ActionDescriptor()).putReference(s2t("null"), r);
    d.putObject(s2t("to"), s2t("layerEffects"), fx);
    executeAction(s2t("set"), d, DialogModes.NO);
}

 

* I do not take into account the case when the effect contains several fills (since I do not fully understand your task and what needs to be done in this situation)

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
Valorous Hero ,
Jul 22, 2021 Jul 22, 2021

Copy link to clipboard

Copied

When fx == new ActionDescriptor(), then fx.erase() throws an error ("Unknown exception") for 2020 .
And what about 2021?

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 ,
Jul 22, 2021 Jul 22, 2021

Copy link to clipboard

Copied

Error. Did not checked moment wint new desc. Updated the code.

 

I have not noticed any discrepancies in the effect lists in recent versions of Photoshop. On the other hand, I don't use the json property often.

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
Valorous Hero ,
Jul 23, 2021 Jul 23, 2021

Copy link to clipboard

Copied

quote

Error. Did not checked moment wint new desc. Updated the code.

 

I have not noticed any discrepancies in the effect lists in recent versions of Photoshop. On the other hand, I don't use the json property often.


By @jazz-y

 

1. Вторую пару

(r = new ActionReference()).putProperty(s2t("property"), s2t("layerEffects"));
    r.putEnumerated(s2t("layer"), s2t("ordinal"), s2t("targetEnum"));

 тоже можно выкинуть. Уже задано... : )

 

2. А если создать два эффекта, потом один удалить, что в json и в layerEffects ?

 

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 ,
Jul 23, 2021 Jul 23, 2021

Copy link to clipboard

Copied

... я приехал из отпуска в час ночи после 12 часов дороги и с чугунной головой сел за комп. Вообще удивительно, что код работает 🙂

 

Да, если сделать два эффекта а один удалить, то в json мульти, а в layerEffects не мульти. Причем этот момент дублируется и в интерфейсе - в палитре слоев эффект удален, но если зайти в эффекты он там висит как выключенный. Возможно json - это не просто свойство слоя (я его слепила для того чтоб было), а используюемый движком интерфейса объект.

 

 

 

 

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
Valorous Hero ,
Jul 23, 2021 Jul 23, 2021

Copy link to clipboard

Copied

Код очень классный. Если заменить "solodFill" на переменную с названием эффекта, то будет работать для всех эффектов в котрых есть "color". Работает даже если док в режиме цмик.

 

 

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 ,
Jul 13, 2021 Jul 13, 2021

Copy link to clipboard

Copied

I have been looking around and it is not easy to find an answer and what I did find appears to be very complex. I'm pretty sure that it is possible to change specific values in layer style effects without removing unchanged effects, but way beyond my current ability.

 

@r-bin  @jazz-y  @Kukurykus as mentioned by JJMack are the usual suspects for this deep level of AM knowledge, perhaps one of them will receive their mention notification and chime in...

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
LEGEND ,
Jul 13, 2021 Jul 13, 2021

Copy link to clipboard

Copied

I played with it, but that was over a year ago and now is beyond my interest. Wait for others ‌‌:D

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 ,
Jul 14, 2021 Jul 14, 2021

Copy link to clipboard

Copied

I would be glad to help, but now on a long journey without a computer.

 

To save the current effect settings, they must first be obtained and written to the "descriptor" variable

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 ,
Jul 13, 2021 Jul 13, 2021

Copy link to clipboard

Copied

@Symo470  

 

EDIT: Back to the drawing board, I thought that I was onto something but it was not that easy...

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 ,
Jul 16, 2021 Jul 16, 2021

Copy link to clipboard

Copied

OK,

So I found a solution with JSON-Action-Manager. Anyone had any success with this? It seems very comprehensive and professional. I have impletemented it somewhat successfully and it does exactly what it says it will do with a big exception - Calling the appropriate jamStyle functions requires me to have pauses built into my script so Photoshop can catch up. I know this doesn't sound right, and perhaps its just my amateur coding, but if step through my code, waiting a few seconds after calling jamStyles.getLayerStyle() it works, but if I let it run quickly, it throws errors. It has taken me quite a while and heaps of trouble shooting to figure this out!

Is this typical of a) Javascript b) Photoshop or c) Extendscript?

Is there a function or a process to wait for Photoshop to catchup before proceeding to the next line of scripting code? The script seems to create temporary Layer styles in the Layer styles palette and my version of PS2021 then goes ahead and syncs them to my creative cloud account, so perhaps having to wait for that process is what is causing the crash? Is there a way to turn this feature off?

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 ,
Jul 16, 2021 Jul 16, 2021

Copy link to clipboard

Copied

WOW. It was the CC Sync causing the issues! Ive turned it off and works seemlessly.

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
LEGEND ,
Jul 17, 2021 Jul 17, 2021

Copy link to clipboard

Copied

Where and what is CC Sync?

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 ,
Jul 17, 2021 Jul 17, 2021

Copy link to clipboard

Copied

CC - Creative Cloud.

So when you update a layerStyle, Photoshop is constantly attempting to sync your new custom layer style to your cloud account. This appears to have been the issue.

NOTE: I'm still having random issues, but hopefully squashing the bugs out one by one.

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
LEGEND ,
Jul 17, 2021 Jul 17, 2021

Copy link to clipboard

Copied

It's inconvenient to launch Photoshop and each time for its session log out from CC.

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
Valorous Hero ,
Jul 17, 2021 Jul 17, 2021

Copy link to clipboard

Copied

Some strange this jamStyles. It is written that it was tested on CS4.

 

getLayerStyle works crookedly, does not always give the correct parameters in the returned object.

 

setLayerStyle is also clumsy, there are problems with enumerated values.

Doesn't understand Multi-effects correctly.

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
LEGEND ,
Jul 17, 2021 Jul 17, 2021

Copy link to clipboard

Copied

Did you tested it with CS4 where maybe that works still correctly or in latter Ps?

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
Valorous Hero ,
Jul 17, 2021 Jul 17, 2021

Copy link to clipboard

Copied

It seems to work on CS6 without problems. Didn't particularly test it. But it works disgustingly for 2020. Since the structure of styles has been greatly changed in the latest versions, there can be a lot of confusion. Even in the absence of styles, but provided that they were once in the layer, it is very difficult to understand what needs to be changed in this layer.

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
LEGEND ,
Jul 17, 2021 Jul 17, 2021

Copy link to clipboard

Copied

From some Ps after CS4 you can add more than one style of same kind. That may be issue.

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