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

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

Community Beginner ,
Nov 17, 2024 Nov 17, 2024

Copy link to clipboard

Copied

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

 

layer-to-mask.png

TOPICS
Actions and scripting

Views

135

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

Community Expert , Nov 17, 2024 Nov 17, 2024

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

 

apply-image.png

 

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( "
...

Votes

Translate

Translate
Adobe
Community Expert ,
Nov 17, 2024 Nov 17, 2024

Copy link to clipboard

Copied

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

 

apply-image.png

 

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.

Votes

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 ,
Nov 18, 2024 Nov 18, 2024

Copy link to clipboard

Copied

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? 

Votes

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 ,
Nov 18, 2024 Nov 18, 2024

Copy link to clipboard

Copied

LATEST

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.

Votes

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 ,
Nov 18, 2024 Nov 18, 2024

Copy link to clipboard

Copied

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!

Votes

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