Hello!
Can you help me, how I can get information about selection on activeDocument by UXP: is selection exists, bounds?
Thanks…
but how I can use it in JS-code? (((
Did you select Type: Document
?
yes, i find, sorry, but dont understand how to use it in JavaScript
Try this
async function getSelectionBounds() {
try {
const result = await require("photoshop").action.batchPlay(
[{
"_obj": "get",
"_target": [{
"_property": "selection"
},
{
"_ref": "document",
"_enum": "ordinal",
"_value": "targetEnum"
}
]
}], {
"synchronousExecution": false,
});
const left = result[0].selection.left._value;
const top = result[0].selection.top._value;
const right = result[0].selection.right._value;
const bottom = result[0].selection.bottom._value;
selBounds = [left, top, right, bottom];
selectionExists = true;
} catch (e) {
selectionExists = false;
}
}
Because there’s no selection present, therefore there’s no result[0]
There are multiple ways to handle this. Eg.
selectionExists = typeof result[0] !== 'undefined';
Could you show Console output? And a relevant part of code would be useful also
I believe you’re trying to use result
variable somewhere, where it’s not defined. Here’s the exact same code @matakus provided, but with some logs and it works just fine
OK, I won’t say exactly what the error is, but you’re not actually running the code me or @matakus has provided. Check line by line and will find the difference. Not sure why you expect result[0]
to be there, when you removed parts of code and now result is a Promise
@Nonparel, did you find it?
Did you select all messages to show in Console?
There should be at least an error if log()
failed.
Anyway, what do you get if you remove async/await
(like you had before) and change to "synchronousExecution": true
in batchPlay?
Sorry, I just don’t know what to say. Feels like some crucial info is missing that’s not in the code
is it important, what version of Photoshop is used? OS version?
(Mac OS 10.15.7 Catalina & Photoshop v 23.1.0)
What does just result
log? (instead of result[0]
)