Skip to main content
yon1313
Known Participant
May 31, 2019
Answered

Add a Layer Style (Stroke)

  • May 31, 2019
  • 3 replies
  • 7565 views

Hi guys,

I trying to add a Layer Style Stroke width extendScript.

i'm trying this code but it doesn't work.

here is my code:

var layer = app.project.item(1).layer(1);

layer.property("ADBE Layer Styles").addProperty("Stroke");

What I did wrong?

Correct answer Tomas Sinkunas

Thank you for your answer.

You can check and see the problem / bug yourself, to see the problem please act according to the instructions and do nothing extra.

You will need to close and restart After Effects, and then open a new Comp and open a new Solid and then run the script (which creates the Strok) and you will see that it does not work.

Do you have any idea how to solve this?

If you do other actions like delete layer and create a new one the script will work, but when I do the extra action in the code in the extenscript code it does not work.

Thank you very much, very much appreciate your help!


Indeed. You are correct. No LS Stroke is added in freshly launched AE with a solid.

As a workaround, you could do a following:

1. Create a new Solid and right click to add Layer Styles -> Stroke

2. Twirl down Layer Styles property under the Solid and select Stroke property (make sure nothing else is selected in the timeline).

3. Go to Animation menu and select Save Animation Preset. This will save an FFX file with Stroke layer style with its current values.

4. In your script, do the following:

var strokeFFX = new File('pathToStroke.ffx');

if (!strokeFFX.exists) {

    throw new Error ('File does not exist at path ' + strokeFFX.fsName);

}

layer.applyPreset(strokeFFX);

var ls = layer.property('ADBE Layer Styles');

var lsStrokeProperty = ls.property('frameFX/enabled');

Keep in mind, that FFX files are not backward compatible. So if you need your script to run on CS6, you'll have to save this stroke FFX file from AE CS6.

Cheers.

3 replies

Participant
May 12, 2022
app.executeCommand(9008);
layer.propertyGroup(2).property(7).property(11).Color.setValue([1, 1, 1]);
layer.propertyGroup(2).property(7).property(11).Size.setValue(2);
Tomas B. aka Tom10
Inspiring
July 8, 2019

Thats an interesting thing.

It is possible to access the 'Layer Styles' Stroke, even though it is not applied to the layer currently.

See this:

app.project.activeItem.layer(1).property("ADBE Layer Styles").property(11)

In addition to this, only the 'Stroke' has strange matchName, which does not relate to the style itself. All others instead of 'frameFX' has their title.

Now while I couldn't make this to work, maybe it will give some ideas to dig through.

P.S. addProperty does not work

Tomas Sinkunas
Legend
July 8, 2019

FYI here's the list of command IDs I'm using in my compCode script to enable Layer Styles. Also, make sure you have composition open and layer selected before executing any of those. Cheers.

app.executeCommand(9000); //Layer Styles - Drop Shadow

app.executeCommand(9001); //Layer Styles - Inner Shadow

app.executeCommand(9002); //Layer Styles - Outer Glow

app.executeCommand(9003); //Layer Styles - Inner Glow

app.executeCommand(9004); //Layer Styles - Bevel and Emboss

app.executeCommand(9005); //Layer Styles - Satin

app.executeCommand(9006); //Layer Styles - Color Overlay

app.executeCommand(9007); //Layer Styles - Gradient Overlay

app.executeCommand(9008); //Layer Styles - Stroke

yon1313
yon1313Author
Known Participant
July 9, 2019

Thanks tomas,

I have already the this code:

app.executeCommand(9008); //Layer Styles - Stroke

But he has a bug, When I open the AE and create a new composition and a new layer, this command does not work.

Do you have any idea why this is happening?

By the way my new comp and layer are selected.

zlovatt
Inspiring
May 31, 2019

From my understanding, layer styles can't be enabled that way; you'd need to go about it by executing the command ID--

var commandID = app.findMenuCommandId("Stroke");

app.executeCommand(commandID);

yon1313
yon1313Author
Known Participant
May 31, 2019

Thanks for your answer,

I wonder if there's a way to do this with a normal code not in Command, because as far that i know the command not available for After Effects version lower then cc 2014.

Thanks again

zlovatt
Inspiring
May 31, 2019

As far as I know, command IDs are the only way to do it.

I can confirm that the above method works from AE 16.1 (CC2019) down to AE 11.0 (CS6), though. That's at least seven years of versions covered