Skip to main content
Participant
November 18, 2024
Answered

PS script image to layerset mask // image alpha to mask

  • November 18, 2024
  • 3 replies
  • 477 views

Hi community,

I try to create a layerset mask from artlayer. Basically I want to copy an artlayer to a layer group mask.

(I am 3D rendering images and alpha channels, import them as layers and want to use the alpha layer as mask of a layer group)

 

My script is working fine so far, I even managed to create a layerset mask and to copy the artlayer (alpha chanel) to the clipboard by script. But I am not able to paste this into the layerset mask.

 

Any hint or idea how to suceeed? Thanks, Niclas

 

This topic has been closed for replies.
Correct answer Stephen Marsh

I prefer to use the apply image command for this task:

 

 

Presuming ExtendScript over UXP, target the destination layer group mask, then:

 

applyImageEvent("Alpha"); // string for the source layer name

function applyImageEvent(layerName) {
	var s2t = function (s) {
		return app.stringIDToTypeID(s);
	};
	var descriptor = new ActionDescriptor();
	var descriptor2 = new ActionDescriptor();
	var reference = new ActionReference();
	reference.putEnumerated( s2t( "channel" ), s2t( "channel" ), s2t( "RGB" ));
	reference.putName( s2t( "layer" ), layerName ); // source layer name
	descriptor2.putReference( s2t( "to" ), reference );
	descriptor2.putBoolean(s2t("preserveTransparency"), true );
	descriptor.putObject( s2t( "with" ), s2t( "calculation" ), descriptor2 );
	executeAction( s2t( "applyImageEvent" ), descriptor, DialogModes.NO );
}

 

If there are multiple layer names called "Alpha" then this will use the first layer name found, which may or may not be problematic.

 

P.S. If you do need to use copy/paste, ensure that you are targeting the correct destination and you may also need to enable and disable channel visibility.

 

Otherwise, you can load the composite/component RGB channel as a selection and create a new layer mask on the group using that selection.

3 replies

Participant
November 18, 2024

Hi Stephen, works like a charm! I tested it with various layer sources - thanks to the source layer name parameter! Perfect!

I can even use this for further experiments... For example with adjustement layer masks. If I use the shadow pass from my 3d rendering software, copy it into an adjustement layer Hue/Saturation, I will be able to colorize the shadows light blue or to lighten the shadows.

 

Thank you very much!

c.pfaffenbichler
Community Expert
Community Expert
November 18, 2024

RGB-ing a grayscale image and then grayscaling it  again is not an ideal approach. 

Why don’t you use it as a Layer Mask right away? 

Participant
November 18, 2024

I dont know exactly what you mean, but it works for me. Perhaps to clarify:
After importing .exr files in Photoshop (via 3D-io photoshop plugin https://www.exr-io.com/reading-openexr-files/), the alpha information is not stored in image alpha channel, but as a layer. And I need the alpha to be in a layerset mask.

Stephen Marsh
Community Expert
Stephen MarshCommunity ExpertCorrect answer
Community Expert
November 18, 2024

I prefer to use the apply image command for this task:

 

 

Presuming ExtendScript over UXP, target the destination layer group mask, then:

 

applyImageEvent("Alpha"); // string for the source layer name

function applyImageEvent(layerName) {
	var s2t = function (s) {
		return app.stringIDToTypeID(s);
	};
	var descriptor = new ActionDescriptor();
	var descriptor2 = new ActionDescriptor();
	var reference = new ActionReference();
	reference.putEnumerated( s2t( "channel" ), s2t( "channel" ), s2t( "RGB" ));
	reference.putName( s2t( "layer" ), layerName ); // source layer name
	descriptor2.putReference( s2t( "to" ), reference );
	descriptor2.putBoolean(s2t("preserveTransparency"), true );
	descriptor.putObject( s2t( "with" ), s2t( "calculation" ), descriptor2 );
	executeAction( s2t( "applyImageEvent" ), descriptor, DialogModes.NO );
}

 

If there are multiple layer names called "Alpha" then this will use the first layer name found, which may or may not be problematic.

 

P.S. If you do need to use copy/paste, ensure that you are targeting the correct destination and you may also need to enable and disable channel visibility.

 

Otherwise, you can load the composite/component RGB channel as a selection and create a new layer mask on the group using that selection.