Copy link to clipboard
Copied
Hello,
@r-bin created function to get the top-left coords, how to reverse it and have the top-right coords?
Here is the function:
function get_layer_bounds(layer){
try{
if (layer.kind == LayerKind.SMARTOBJECT){
var layer0 = activeDocument.activeLayer;
activeDocument.activeLayer = layer;
var r = new ActionReference();
r.putEnumerated( charIDToTypeID( "Lyr " ), charIDToTypeID( "Ordn" ), charIDToTypeID( "Trgt" ) );
var d = executeActionGet(r).getObjectValue(stringIDToTypeID("smartObjectMore")).getList(stringIDToTypeID("transform"));
var x = [d.getDouble(0), d.getDouble(2), d.getDouble(4), d.getDouble(6)];
var y = [d.getDouble(1), d.getDouble(3), d.getDouble(5), d.getDouble(7)];
var l = [Math.min(x[0], Math.min(x[1], Math.min(x[2], x[3]))) ];
var r = [Math.max(x[0], Math.max(x[1], Math.max(x[2], x[3]))) ];
var t = [Math.min(y[0], Math.min(y[1], Math.min(y[2], y[3]))) ];
var b = [Math.max(y[0], Math.max(y[1], Math.max(y[2], y[3]))) ];
activeDocument.activeLayer = layer0;
return [ UnitValue(l,"px"), UnitValue(t,"px"), UnitValue(r,"px"), UnitValue(b,"px") ];
} else
return layer.boundsNoEffects;
}
catch (e) { alert(e); }
}
Thanks you
function get_bound(layer){
//return top-right position
var position = [layer.bounds[2].value,layer.bounds[1].value];
return position;
}
Copy link to clipboard
Copied
function getCoordinates(topleft){
var bounds = app.activeDocument.selection.bounds
var coordinates = {
topleft: [bounds[0],bounds[1]],
bottomright: [bounds[2],bounds[3]]
}
return topleft ? coordinates.topleft : coordinates.bottomright;
}
alert("top left coordinates: "+getCoordinates(true));
alert("bottom right coordinates: "+getCoordinates(false));
Here's some samplec code that will do what you want. Hope it helps you.
Copy link to clipboard
Copied
Hello,
I need top-right already have the top-left coords with the function, thanks you
Copy link to clipboard
Copied
Why don’t you combine the y and the x coordinates you want yourself?
Copy link to clipboard
Copied
Using my function that would be a combination of bounds[0] & bounds[3].
You can do it! 🙂
Copy link to clipboard
Copied
function get_bound(layer){
//return top-right position
var position = [layer.bounds[2].value,layer.bounds[1].value];
return position;
}
Copy link to clipboard
Copied
Maybe x[1] and y[1]?
Copy link to clipboard
Copied