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

How to make a stroke layer style using a script?

New Here ,
Dec 09, 2022 Dec 09, 2022

Copy link to clipboard

Copied

Is there a way to create a stroke layer style that automatically uses the foreground color and a gradient stroke using the foreground and background colors?

TOPICS
Actions and scripting , Windows

Views

568

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 2 Correct answers

Community Expert , Dec 09, 2022 Dec 09, 2022

The following script will set a new stroke style using the foreground colour:

 

// Get the foreground RGB values
var fR = foregroundColor.rgb.red;
var fG = foregroundColor.rgb.green;
var fB = foregroundColor.rgb.blue;

// Set the stroke style
setStrokeStyle(100, true, true, true, "insetFrame", "normal", 100, 3, fR, fG, fB, false);

function setStrokeStyle(scale, enabled, present, showInDialog, position, blend, opacity, size, red, grain, blue, overprint) {
	var s2t = function (s) {
		return app.s
...

Likes

Translate

Translate
Community Expert , Dec 09, 2022 Dec 09, 2022

This one creates a gradient stroke style using a gradient preset of "Foreground to Background". The gradient-related values are at defaults.

 

// Uses a gradient preset named "Foreground to Background"

// Get the foreground RGB values
var fR = foregroundColor.rgb.red;
var fG = foregroundColor.rgb.green;
var fB = foregroundColor.rgb.blue;

// Get the background RGB values
var bR = backgroundColor.rgb.red;
var bG = backgroundColor.rgb.green;
var bB = backgroundColor.rgb.blue;

setGradStrokeStyle(
...

Likes

Translate

Translate
Community Expert ,
Dec 09, 2022 Dec 09, 2022

Copy link to clipboard

Copied

You can not achieve this using Photoshop actions, it will record colors used. Maybe using script. @jazz-y @r-bin @c.pfaffenbichler @Stephen_A_Marsh 

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
Community Expert ,
Dec 09, 2022 Dec 09, 2022

Copy link to clipboard

Copied

The following script will set a new stroke style using the foreground colour:

 

// Get the foreground RGB values
var fR = foregroundColor.rgb.red;
var fG = foregroundColor.rgb.green;
var fB = foregroundColor.rgb.blue;

// Set the stroke style
setStrokeStyle(100, true, true, true, "insetFrame", "normal", 100, 3, fR, fG, fB, false);

function setStrokeStyle(scale, enabled, present, showInDialog, position, blend, opacity, size, red, grain, blue, overprint) {
	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 );
	descriptor2.putUnitDouble( s2t( "scale" ), s2t( "percentUnit" ), scale );
	descriptor3.putBoolean( s2t( "enabled" ), enabled );
	descriptor3.putBoolean( s2t( "present" ), present );
	descriptor3.putBoolean( s2t( "showInDialog" ), showInDialog );
	descriptor3.putEnumerated( s2t( "style" ), s2t( "frameStyle" ), s2t( position )); // "insetFrame" | "outsetFrame" | "centeredFrame"
	descriptor3.putEnumerated( s2t( "paintType" ), s2t( "frameFill" ), s2t( "solidColor" ));
	descriptor3.putEnumerated( s2t( "mode" ), s2t( "blendMode" ), s2t( blend ));
	descriptor3.putUnitDouble( s2t( "opacity" ), s2t( "percentUnit" ), opacity );
	descriptor3.putUnitDouble( s2t( "size" ), s2t( "pixelsUnit" ), size );
	descriptor4.putDouble( s2t( "red" ), red );
	descriptor4.putDouble( s2t( "grain" ), grain );
	descriptor4.putDouble( s2t( "blue" ), blue );
	descriptor3.putObject( s2t( "color" ), s2t( "RGBColor" ), descriptor4 );
	descriptor3.putBoolean( s2t( "overprint" ), overprint );
	descriptor2.putObject( s2t( "frameFX" ), s2t( "frameFX" ), descriptor3 );
	descriptor.putObject( s2t( "to" ), s2t( "layerEffects" ), descriptor2 );
	executeAction( s2t( "set" ), descriptor, DialogModes.NO );
}

 

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
Community Expert ,
Dec 09, 2022 Dec 09, 2022

Copy link to clipboard

Copied

This one creates a gradient stroke style using a gradient preset of "Foreground to Background". The gradient-related values are at defaults.

 

// Uses a gradient preset named "Foreground to Background"

// Get the foreground RGB values
var fR = foregroundColor.rgb.red;
var fG = foregroundColor.rgb.green;
var fB = foregroundColor.rgb.blue;

// Get the background RGB values
var bR = backgroundColor.rgb.red;
var bG = backgroundColor.rgb.green;
var bB = backgroundColor.rgb.blue;

setGradStrokeStyle(100, true, true, true, 100, 3, 128, 128, 128, "Foreground to Background", 4096, fR, fG, fB, 0, 50, bR, bG, bB, 4096, 50, 100, 0, 50, 100, 4096, 50, 90, false, false, 100, true, 0, 0, false);

function setGradStrokeStyle(scale, enabled, present, showInDialog, opacity, size, red, grain, blue, name2, interfaceIconFrameDimmed, red2, grain2, blue2, location, midpoint, red3, grain3, blue3, location2, midpoint2, opacity2, location3, midpoint3, opacity3, location4, midpoint4, angle, reverse, dither, scale2, align, horizontal, vertical, overprint) {
	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 descriptor5 = new ActionDescriptor();
	var descriptor6 = new ActionDescriptor();
	var descriptor7 = new ActionDescriptor();
	var descriptor8 = new ActionDescriptor();
	var descriptor9 = new ActionDescriptor();
	var descriptor10 = new ActionDescriptor();
	var descriptor11 = new ActionDescriptor();
	var descriptor12 = new ActionDescriptor();
	var list = new ActionList();
	var list2 = new ActionList();
	var reference = new ActionReference();

	reference.putProperty( s2t( "property" ), s2t( "layerEffects" ));
	reference.putEnumerated( s2t( "layer" ), s2t( "ordinal" ), s2t( "targetEnum" ));
	descriptor.putReference( s2t( "null" ), reference );
	descriptor2.putUnitDouble( s2t( "scale" ), s2t( "percentUnit" ), scale );
	descriptor3.putBoolean( s2t( "enabled" ), enabled );
	descriptor3.putBoolean( s2t( "present" ), present );
	descriptor3.putBoolean( s2t( "showInDialog" ), showInDialog );
	descriptor3.putEnumerated( s2t( "style" ), s2t( "frameStyle" ), s2t( "insetFrame" ));
	descriptor3.putEnumerated( s2t( "paintType" ), s2t( "frameFill" ), s2t( "gradientFill" ));
	descriptor3.putEnumerated( s2t( "mode" ), s2t( "blendMode" ), s2t( "normal" ));
	descriptor3.putUnitDouble( s2t( "opacity" ), s2t( "percentUnit" ), opacity );
	descriptor3.putUnitDouble( s2t( "size" ), s2t( "pixelsUnit" ), size );
	descriptor4.putDouble( s2t( "red" ), red );
	descriptor4.putDouble( s2t( "grain" ), grain );
	descriptor4.putDouble( s2t( "blue" ), blue );
	descriptor3.putObject( s2t( "color" ), s2t( "RGBColor" ), descriptor4 );
	descriptor5.putString( s2t( "name" ), name2 );
	descriptor5.putEnumerated( s2t( "gradientForm" ), s2t( "gradientForm" ), s2t( "customStops" ));
	descriptor5.putDouble( s2t( "interfaceIconFrameDimmed" ), interfaceIconFrameDimmed );
	descriptor7.putDouble( s2t( "red" ), red2 );
	descriptor7.putDouble( s2t( "grain" ), grain2 );
	descriptor7.putDouble( s2t( "blue" ), blue2 );
	descriptor6.putObject( s2t( "color" ), s2t( "RGBColor" ), descriptor7 );
	descriptor6.putEnumerated( s2t( "type" ), s2t( "colorStopType" ), s2t( "userStop" ));
	descriptor6.putInteger( s2t( "location" ), location );
	descriptor6.putInteger( s2t( "midpoint" ), midpoint );
	list.putObject( s2t( "colorStop" ), descriptor6 );
	descriptor9.putDouble( s2t( "red" ), red3 );
	descriptor9.putDouble( s2t( "grain" ), grain3 );
	descriptor9.putDouble( s2t( "blue" ), blue3 );
	descriptor8.putObject( s2t( "color" ), s2t( "RGBColor" ), descriptor9 );
	descriptor8.putEnumerated( s2t( "type" ), s2t( "colorStopType" ), s2t( "userStop" ));
	descriptor8.putInteger( s2t( "location" ), location2 );
	descriptor8.putInteger( s2t( "midpoint" ), midpoint2 );
	list.putObject( s2t( "colorStop" ), descriptor8 );
	descriptor5.putList( s2t( "colors" ), list );
	descriptor10.putUnitDouble( s2t( "opacity" ), s2t( "percentUnit" ), opacity2 );
	descriptor10.putInteger( s2t( "location" ), location3 );
	descriptor10.putInteger( s2t( "midpoint" ), midpoint3 );
	list2.putObject( s2t( "transferSpec" ), descriptor10 );
	descriptor11.putUnitDouble( s2t( "opacity" ), s2t( "percentUnit" ), opacity3 );
	descriptor11.putInteger( s2t( "location" ), location4 );
	descriptor11.putInteger( s2t( "midpoint" ), midpoint4 );
	list2.putObject( s2t( "transferSpec" ), descriptor11 );
	descriptor5.putList( s2t( "transparency" ), list2 );
	descriptor3.putObject( s2t( "gradient" ), s2t( "gradientClassEvent" ), descriptor5 );
	descriptor3.putUnitDouble( s2t( "angle" ), s2t( "angleUnit" ), angle );
	descriptor3.putEnumerated( s2t( "type" ), s2t( "gradientType" ), s2t( "linear" ));
	descriptor3.putBoolean( s2t( "reverse" ), reverse );
	descriptor3.putBoolean( s2t( "dither" ), dither );
	descriptor3.putUnitDouble( s2t( "scale" ), s2t( "percentUnit" ), scale2 );
	descriptor3.putBoolean( s2t( "align" ), align );
	descriptor12.putUnitDouble( s2t( "horizontal" ), s2t( "percentUnit" ), horizontal );
	descriptor12.putUnitDouble( s2t( "vertical" ), s2t( "percentUnit" ), vertical );
	descriptor3.putObject( s2t( "offset" ), s2t( "paint" ), descriptor12 );
	descriptor3.putBoolean( s2t( "overprint" ), overprint );
	descriptor2.putObject( s2t( "frameFX" ), s2t( "frameFX" ), descriptor3 );
	descriptor.putObject( s2t( "to" ), s2t( "layerEffects" ), descriptor2 );
	executeAction( s2t( "set" ), descriptor, DialogModes.NO );
}

 

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
New Here ,
Dec 10, 2022 Dec 10, 2022

Copy link to clipboard

Copied

Thank you, this script runs perfectly.

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
Community Expert ,
Dec 10, 2022 Dec 10, 2022

Copy link to clipboard

Copied

LATEST

You're welcome.

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