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

get top-right coords of a layer

Community Beginner ,
Jun 30, 2021 Jun 30, 2021

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

TOPICS
Actions and scripting

Views

237

Translate

Translate

Report

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 1 Correct answer

Community Beginner , Jun 30, 2021 Jun 30, 2021
function get_bound(layer){ 

    //return top-right position
    var position = [layer.bounds[2].value,layer.bounds[1].value]; 

    return position;
}

Votes

Translate

Translate
Adobe
Contributor ,
Jun 30, 2021 Jun 30, 2021

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.

Votes

Translate

Translate

Report

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 Beginner ,
Jun 30, 2021 Jun 30, 2021

Copy link to clipboard

Copied

Hello,

 

I need top-right already have the top-left coords with the function, thanks you

Votes

Translate

Translate

Report

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 ,
Jun 30, 2021 Jun 30, 2021

Copy link to clipboard

Copied

Why don’t you combine the y and the x coordinates you want yourself? 

Votes

Translate

Translate

Report

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
Contributor ,
Jun 30, 2021 Jun 30, 2021

Copy link to clipboard

Copied

Using my function that would be a combination of bounds[0] & bounds[3].

You can do it! 🙂

Votes

Translate

Translate

Report

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 Beginner ,
Jun 30, 2021 Jun 30, 2021

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

Votes

Translate

Translate

Report

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
LEGEND ,
Jun 30, 2021 Jun 30, 2021

Copy link to clipboard

Copied

Maybe x[1] and y[1]?

Votes

Translate

Translate

Report

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
People's Champ ,
Jul 01, 2021 Jul 01, 2021

Copy link to clipboard

Copied

LATEST
If still relevant, then
 
I did not understand the question.
It seems like the function returns an array from [right, top, left, bottom].
What does top-left and top-right have to do with?
What do you want to use this function for?
Please attach a screenshot with the explanations.
 
 
 

Votes

Translate

Translate

Report

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