I’m creating a generative AI plugin (open source and free to use) for photoshop.
You make a selection using Lasso, Brush selection tool or any tool. and give a prompt.
but I’m not able to detect the selection.
can anybody guide me how can i reliably detect selection and generate a mask based on it.
To get selection state I use this descriptor in BatchPlay:
[
{
_obj: "get",
_target: [
{ _property: "selection" },
{ _ref: "document", _enum: "ordinal", _value: "targetEnum" },
],
},
]
And I do it on these events:
["close", "layersFiltered", "historyStateChanged", "modalJavaScriptScopeExit"]
To create a mask I also use BatchPlay with this descriptor:
[{
_obj: "make",
new: { _class: "channel" },
at: { _ref: "channel", _enum: "channel", _value: "mask" },
using: { _enum: "userMaskEnabled", _value: value },
}]
Where value is one of reveal|hide
1 Like
@imtheonly1, did you manage to make it work? Update would be nice 
Thanks, I was able to figure out selection and mask generation.
But I’ve a new problem now.
Let’s say my plugin downloads an image, and I want to open it as a new layer in an existing active document.
If one of the answers solved the problem, it would be great to mark it as a solution by ticking the box at the bottom of the post. If you found a different solution, would be nice if you shared it and marked that post as a solution 
About opening an image it would be better to create a separate topic 