Add a Layer Style (Stroke)

Participant ,
May 31, 2019 May 31, 2019

Copy link to clipboard

Copied

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?

TOPICS
Scripting

Views

1.4K

Likes

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

Adobe Community Professional , Jul 10, 2019 Jul 10, 2019
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 -> Stroke2. 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 str...

Likes

Translate

Translate
Contributor ,
May 31, 2019 May 31, 2019

Copy link to clipboard

Copied

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);

Likes

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
Participant ,
May 31, 2019 May 31, 2019

Copy link to clipboard

Copied

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

Likes

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
Contributor ,
May 31, 2019 May 31, 2019

Copy link to clipboard

Copied

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

Likes

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
Participant ,
Jul 08, 2019 Jul 08, 2019

Copy link to clipboard

Copied

  1. var commandID = app.findMenuCommandId("Stroke"); 
  2. app.executeCommand(commandID); 

This does not work well, because it brings the effect "stroke" rather than the "Layer Style Stroke".

Likes

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
Contributor ,
Jul 08, 2019 Jul 08, 2019

Copy link to clipboard

Copied

Can you show a screenshot of this happening? What version of AE? I've never seen this behaviour.

Likes

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
Participant ,
Jul 08, 2019 Jul 08, 2019

Copy link to clipboard

Copied

Maybe I was not clear enough,

It does not apply the "Layer Style Stroke" on the layer, instead it applys the "Stroke" effect.

Thanks.

Screenshot attached.

Likes

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
Contributor ,
Jul 08, 2019 Jul 08, 2019

Copy link to clipboard

Copied

You were clear, I've just never seen this before and I can't reproduce it in any version of AE.  See: Imgur

Can you manually add a stroke layer style to a layer, and take a screenshot of what that looks like?

Likes

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
Participant ,
Jul 08, 2019 Jul 08, 2019

Copy link to clipboard

Copied

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

Likes

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
Adobe Community Professional ,
Jul 08, 2019 Jul 08, 2019

Copy link to clipboard

Copied

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

Likes

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
Participant ,
Jul 08, 2019 Jul 08, 2019

Copy link to clipboard

Copied

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.

Likes

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
Adobe Community Professional ,
Jul 09, 2019 Jul 09, 2019

Copy link to clipboard

Copied

Well, this quick test added Layer Styles - Stroke to a Solid layer. Not sure why it wouldn't work on your end.

var composition = app.project.activeItem;

if (!composition || !(composition instanceof CompItem)) {

    return alert('Please select composition first');

}

var layer = composition.selectedLayers[0];

if (!layer) {

    return alert('Please select a layer');

}

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

Likes

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
Participant ,
Jul 09, 2019 Jul 09, 2019

Copy link to clipboard

Copied

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!

Likes

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
Adobe Community Professional ,
Jul 10, 2019 Jul 10, 2019

Copy link to clipboard

Copied

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.

Likes

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
Participant ,
Jul 10, 2019 Jul 10, 2019

Copy link to clipboard

Copied

Thanks Tomas,

Do you thinks if I'll save the FFX file from AE CS6 it will work to all adobe versions (cs6 and higher)?

Likes

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
Contributor ,
Jul 10, 2019 Jul 10, 2019

Copy link to clipboard

Copied

Yes. FFX files are forwards-compatible, meaning they'll work in any version newer than the one you saved them in.

Likes

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
Participant ,
Jul 10, 2019 Jul 10, 2019

Copy link to clipboard

Copied

LATEST

Thanks!

Likes

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