Copy link to clipboard
Copied
Hello everyone! How to check the x, y position of the active layer in the document? Grateful for the help.
I tried something like this, but without success.
if (activeDocument.activeLayer.length) {
alert (activeDocument.activeLayer.coordinate);
}
alert (activeDocument.activeLayer.bounds)
That produces an Array of the leftmost, topmost, rightmost and bottommost coordinates.
Copy link to clipboard
Copied
Please elaborate on what you are actually trying to do.
A Script seems like a possible solution.
Copy link to clipboard
Copied
OK! in fact i need to add a text layer having the same location x, y centrally over a layer identified as "target layer", directly without having to create a selection and then use the vertical and horizontal alignment.
If I identify the coordinates of the target layer, then I can move the text layer based on the x, y positions, then center with the data obtained by the width and height of the layer.
Copy link to clipboard
Copied
A Script would be an option but it might be possible to use an Action if you are unfamiliar with Photoshop’s JavaScript DOM and AM-code.
Load Selection from active Layer, create Type Layer, Align, deselect should record in an Action.
Copy link to clipboard
Copied
var Position = 8;
switch (Position){
case 1 : align('AdLf'); align('AdTp'); break;
case 2 : align('AdCH'); align('AdTp'); break;
case 3 : align('AdRg'); align('AdTp'); break;
case 4 : align('AdLf'); align('AdCV'); break;
case 5 : align('AdCH'); align('AdCV'); break;
case 6 : align('AdRg'); align('AdCV'); break;
case 7 : align('AdLf'); align('AdBt'); break;
case 8 : align('AdCH'); align('AdBt'); break;
case 9 : align('AdRg'); align('AdBt'); break;
default : break;
}
function align(method) {
var desc = new ActionDescriptor();
var ref = new ActionReference();
ref.putEnumerated( charIDToTypeID( "Lyr " ), charIDToTypeID( "Ordn" ), charIDToTypeID( "Trgt" ) );
desc.putReference( charIDToTypeID( "null" ), ref );
desc.putEnumerated( charIDToTypeID( "Usng" ), charIDToTypeID( "ADSt" ), charIDToTypeID( method ) );
try{
executeAction( charIDToTypeID( "Algn" ), desc, DialogModes.NO );
}
catch(e){}
}
Yes, I know that method! It is always good to have a plan B, I look for another alternative.
Copy link to clipboard
Copied
You can access the activeLayer’s bounds and calculate the center from that.
Copy link to clipboard
Copied
Exactly! We just need to find the exact position of the target layer in the document. Man, I did a thorough search on the internet and found nothing related, I am almost convinced that this is not possible.
Copy link to clipboard
Copied
You can calculate the center from the Array.
Copy link to clipboard
Copied
Copy link to clipboard
Copied
alert (activeDocument.activeLayer.bounds)
That produces an Array of the leftmost, topmost, rightmost and bottommost coordinates.
Copy link to clipboard
Copied
c.pfaffenbichler I believe that you can start to work, you were brilliant.
Copy link to clipboard
Copied
Sorry it took me so long to understand what you were looking for exactly, I had read the original post sloppily.
Copy link to clipboard
Copied
Thank you very much for your support, this is exactly what I was looking for. Thanks again for sharing your knowledge c.pfaffenbichler .
Find more inspiration, events, and resources on the new Adobe Community
Explore Now