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

Check the layer location

Engaged ,
Sep 07, 2020 Sep 07, 2020

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);
}

 
TOPICS
Actions and scripting
675
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 2 Correct answers

Community Expert , Sep 07, 2020 Sep 07, 2020

 

alert (activeDocument.activeLayer.bounds)

 

That produces an Array of the leftmost, topmost, rightmost and bottommost coordinates. 

Translate
Community Expert , Sep 07, 2020 Sep 07, 2020
var theBounds = activeDocument.activeLayer.bounds;
var theX = theBounds[0] + (theBounds[2] - theBounds[0])/2;
var theY = theBounds[1] + (theBounds[3] - theBounds[1])/2;
alert ("center: "+theX+"_"+theY);
Translate
Adobe
Community Expert ,
Sep 07, 2020 Sep 07, 2020

Please elaborate on what you are actually trying to do. 

 

A Script seems like a possible solution. 

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
Engaged ,
Sep 07, 2020 Sep 07, 2020

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.

Anotação 2020-09-07 102847.png

 

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.

 

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 ,
Sep 07, 2020 Sep 07, 2020

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. 

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
Engaged ,
Sep 07, 2020 Sep 07, 2020

 

 

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.

 

 

 
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 ,
Sep 07, 2020 Sep 07, 2020

You can access the activeLayer’s bounds and calculate the center from that. 

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
Engaged ,
Sep 07, 2020 Sep 07, 2020

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.

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 ,
Sep 07, 2020 Sep 07, 2020

You can calculate the center from the Array. 

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 ,
Sep 07, 2020 Sep 07, 2020
var theBounds = activeDocument.activeLayer.bounds;
var theX = theBounds[0] + (theBounds[2] - theBounds[0])/2;
var theY = theBounds[1] + (theBounds[3] - theBounds[1])/2;
alert ("center: "+theX+"_"+theY);
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 ,
Sep 07, 2020 Sep 07, 2020

 

alert (activeDocument.activeLayer.bounds)

 

That produces an Array of the leftmost, topmost, rightmost and bottommost coordinates. 

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
Engaged ,
Sep 07, 2020 Sep 07, 2020

c.pfaffenbichler I believe that you can start to work, you were brilliant.

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 ,
Sep 07, 2020 Sep 07, 2020

Sorry it took me so long to understand what you were looking for exactly, I had read the original post sloppily. 

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
Engaged ,
Sep 07, 2020 Sep 07, 2020
LATEST

Thank you very much for your support, this is exactly what I was looking for. Thanks again for sharing your knowledge c.pfaffenbichler .

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