Javascipt for add stroke in active image layer

Community Beginner ,
Mar 23, 2021 Mar 23, 2021

Copy link to clipboard

Copied

Hi, 
Can anyone help me with javascript to add one pixel black color solid stroke for the active image layer.

 

Please see the below example.

Karthikeyan98A2_0-1616490001374.png

I need to add stroke for the each images on above frames. Every image in seperate layer.

TOPICS
Actions and scripting, How to

Views

81

Likes

translate

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 , Mar 23, 2021 Mar 23, 2021
I think this one may be better, again cleaned AM code:     layerTransparencyToSelection(); function layerTransparencyToSelection() { var c2t = function (s) { return app.charIDToTypeID(s); }; var s2t = function (s) { return app.stringIDToTypeID(s); }; var descriptor = new ActionDescriptor(); var reference = new ActionReference(); var reference2 = new ActionReference(); reference.putProperty( s2t( "channel" ), s2t( "selection" )); descriptor.putReference( c2t( "null" ), reference )...

Likes

translate

Translate

Translate
Adobe Community Professional ,
Mar 23, 2021 Mar 23, 2021

Copy link to clipboard

Copied

ScriptingListener/Clean SL code for the active layer:

 

strokeStyle(100, true, true, true, 100, 1, 0, 0, 0, false);

function strokeStyle(scale, enabled, present, showInDialog, opacity, size, red, Grn, blue, overprint) {
	var c2t = function (s) {
		return app.charIDToTypeID(s);
	};

	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( c2t( "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( "centeredFrame" ));
	descriptor3.putEnumerated( s2t( "paintType" ), s2t( "frameFill" ), s2t( "solidColor" ));
	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( c2t( "Grn " ), Grn );
	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 );
}

rasterizeLayerFX();
function rasterizeLayerFX() {
	var c2t = function (s) {
		return app.charIDToTypeID(s);
	};

	var s2t = function (s) {
		return app.stringIDToTypeID(s);
	};

	var descriptor = new ActionDescriptor();
	var reference = new ActionReference();

	reference.putEnumerated( s2t( "layer" ), s2t( "ordinal" ), s2t( "targetEnum" ));
	descriptor.putReference( c2t( "null" ), reference );
	descriptor.putEnumerated( s2t( "what" ), s2t( "rasterizeItem" ), s2t( "layerStyle" ));
	executeAction( s2t( "rasterizeLayer" ), descriptor, DialogModes.NO );
}

 

Depending on your needs, you may not need to rasterize the stroke layer style.

 

Likes

translate

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

Copy link to clipboard

Copied

I think this one may be better, again cleaned AM code:

 

 

layerTransparencyToSelection();
function layerTransparencyToSelection() {
	var c2t = function (s) {
		return app.charIDToTypeID(s);
	};

	var s2t = function (s) {
		return app.stringIDToTypeID(s);
	};

	var descriptor = new ActionDescriptor();
	var reference = new ActionReference();
	var reference2 = new ActionReference();

	reference.putProperty( s2t( "channel" ), s2t( "selection" ));
	descriptor.putReference( c2t( "null" ), reference );
	reference2.putEnumerated( s2t( "channel" ), s2t( "channel" ), s2t( "transparencyEnum" ));
	descriptor.putReference( s2t( "to" ), reference2 );
	executeAction(s2t( "set" ), descriptor, DialogModes.NO);
}

defaultForeBack();
function defaultForeBack() {
	var c2t = function (s) {
		return app.charIDToTypeID(s);
	};

	var s2t = function (s) {
		return app.stringIDToTypeID(s);
	};

	var descriptor = new ActionDescriptor();
	var reference = new ActionReference();

	reference.putProperty( s2t( "color" ), s2t( "colors" ));
	descriptor.putReference( c2t( "null" ), reference );
	executeAction( s2t( "reset" ), descriptor, DialogModes.NO );
}

strokeSelection(1, 100, 0, 0, 0);
function strokeSelection(width, opacity, red, Grn, blue) {
	var c2t = function (s) {
		return app.charIDToTypeID(s);
	};

	var s2t = function (s) {
		return app.stringIDToTypeID(s);
	};

	var descriptor = new ActionDescriptor();
	var descriptor2 = new ActionDescriptor();

	descriptor.putInteger( s2t( "width" ), width );
	descriptor.putEnumerated( s2t( "location" ), c2t( "StrL" ), c2t( "Cntr" ));
	descriptor.putUnitDouble( s2t( "opacity" ), s2t( "percentUnit" ), opacity );
	descriptor.putEnumerated( s2t( "mode" ), s2t( "blendMode" ), s2t( "normal" ));
	descriptor2.putDouble( s2t( "red" ), red );
	descriptor2.putDouble( c2t( "Grn " ), Grn );
	descriptor2.putDouble( s2t( "blue" ), blue );
	descriptor.putObject( s2t( "color" ), s2t( "RGBColor" ), descriptor2 );
	executeAction( s2t( "stroke" ), descriptor, DialogModes.NO );
}

app.activeDocument.selection.deselect();

 

 

Likes

translate

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

Copy link to clipboard

Copied

This one was awesome...  Works cool... Thank you very much...

Likes

translate

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