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

Photoshop Javascript : load selection of opaque pixels but not the transparent pixels.

New Here ,
Dec 17, 2018 Dec 17, 2018

Photoshop Javascript : load selection of opaque pixels but not the transparent pixels of a layer.

I really despair to achieve this in a simple javascript script.

I kinda understood I needed to first load a channel, and then perform a selection from this channel, but I just failed doing this. I don't know how to get the corresponding channel that contains the transparent pixels of the current layer.

The original file is a PNG, it has a single layer.

There is no alpha channel, only R, G and B, although the image has transparent areas.

When I go to select, load Selection, Photoshop suggests by default a channel called layer_name+" Transparency",

therefore I tried something like:

doc.selection.load(doc.channels[layer_name + "Transparency"], SelectionType.EXTEND);

But this just failed.

I think I don't understand the way I am supposed to work with selections and channels

Thanks for any help!

Bill

TOPICS
Actions and scripting
2.5K
Translate
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

LEGEND , Dec 17, 2018 Dec 17, 2018

sTT = stringIDToTypeID;

(ref1 = new ActionReference()).putProperty(c = sTT('channel'), sTT('selection'));

(dsc = new ActionDescriptor()).putReference(sTT('null'), ref1);

(ref2 = new ActionReference()).putEnumerated(c, c, sTT('transparencyEnum'))

dsc.putReference(sTT('to'), ref2), executeAction(sTT('set'), dsc);

Translate
Adobe
Community Expert ,
Dec 17, 2018 Dec 17, 2018

Can you load the selection by ctrl/cmd clicking on the layer's thumbnail in the layer panel?

Translate
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 18, 2018 Dec 18, 2018

Hello Chuck,

yes I can.

Translate
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
LEGEND ,
Dec 17, 2018 Dec 17, 2018

sTT = stringIDToTypeID;

(ref1 = new ActionReference()).putProperty(c = sTT('channel'), sTT('selection'));

(dsc = new ActionDescriptor()).putReference(sTT('null'), ref1);

(ref2 = new ActionReference()).putEnumerated(c, c, sTT('transparencyEnum'))

dsc.putReference(sTT('to'), ref2), executeAction(sTT('set'), dsc);

Translate
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 18, 2018 Dec 18, 2018

This seems to be working.

Can you tell me what it does exactly, and how you came up with this solution?

Also I would like to get the coodinates of the bounding box around this selection, can I easily find them?

Can I associate this selection to a selection object in javascript?

Thank you!

Bill

Translate
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 18, 2018 Dec 18, 2018

I found out what I needed

Thank you all!

Bill

Translate
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
LEGEND ,
Dec 18, 2018 Dec 18, 2018
LATEST

You can use ScriptListener to get similar code.

Bounding box coordinates you're taking using:

activeDocument.selection.bounds

I don't know what you mean by last question?

Translate
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 17, 2018 Dec 17, 2018

A Selection includes feathering It may well not a B/W cutout there the gray area. Its a grayscale channel

JJMack
Translate
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