Skip to main content
Innotex Nico Tanne
Inspiring
May 3, 2021
Answered

Coordinates from a frame

  • May 3, 2021
  • 2 replies
  • 3614 views

Hi Hope you can Help me

I need the values from a frame, but i get only the values from Image inside the frame.

How can i get the Frame only values?

 

var doc = app.activeDocument

var layer = doc.layers[0]

alert(layer.bounds[0])

alert(layer.bounds[1])

alert(layer.bounds[2])

alert(layer.bounds[3])

This topic has been closed for replies.
Correct answer r-bin

Check and see which option suits you

 

//////////// option 1

var r = new ActionReference();
r.putProperty(stringIDToTypeID("property"), stringIDToTypeID("bounds"));
r.putEnumerated(stringIDToTypeID("layer"), stringIDToTypeID("ordinal"), stringIDToTypeID("targetEnum"));

var b = executeActionGet(r).getObjectValue(stringIDToTypeID("bounds"));

var bounds = 
[
b.getUnitDoubleValue(stringIDToTypeID("top")), 
b.getUnitDoubleValue(stringIDToTypeID("left")), 
b.getUnitDoubleValue(stringIDToTypeID("right")), 
b.getUnitDoubleValue(stringIDToTypeID("bottom"))
];

alert(bounds, "opt 1")

//////////// option 2

var r = new ActionReference();
r.putProperty(stringIDToTypeID("property"), stringIDToTypeID("framedGroup"));
r.putEnumerated(stringIDToTypeID("layer"), stringIDToTypeID("ordinal"), stringIDToTypeID("targetEnum"));

var b = executeActionGet(r).getObjectValue(stringIDToTypeID("framedGroup")).getObjectValue(stringIDToTypeID("framedGroupRect"));

var bounds = 
[
b.getUnitDoubleValue(stringIDToTypeID("top")), 
b.getUnitDoubleValue(stringIDToTypeID("left")), 
b.getUnitDoubleValue(stringIDToTypeID("right")), 
b.getUnitDoubleValue(stringIDToTypeID("bottom"))
];

alert(bounds, "opt 2")


//////////// option 3 & 4

var d = new ActionDescriptor();
var r = new ActionReference();

r.putProperty(stringIDToTypeID("property"), stringIDToTypeID("json"));
r.putEnumerated(stringIDToTypeID("document"), stringIDToTypeID("ordinal"), stringIDToTypeID("targetEnum"));
d.putReference(stringIDToTypeID("null"), r);

d.putBoolean(stringIDToTypeID("imageInfo"), false); 
d.putBoolean(stringIDToTypeID( "includeAncestors" ), false);
d.putInteger(stringIDToTypeID("layerID"), app.activeDocument.activeLayer.id);

eval("var o="+executeAction(stringIDToTypeID("get"), d, DialogModes.NO).getString(stringIDToTypeID("json")));

// option 3

var bounds = 
[
o.layers[0].path.bounds.top,
o.layers[0].path.bounds.left,
o.layers[0].path.bounds.right,
o.layers[0].path.bounds.bottom,
];

alert(bounds, "opt 3");

// option 4

var bounds = 
[
o.layers[0].path.pathComponents[0].origin.bounds.top,
o.layers[0].path.pathComponents[0].origin.bounds.left,
o.layers[0].path.pathComponents[0].origin.bounds.right,
o.layers[0].path.pathComponents[0].origin.bounds.bottom,
];

alert(bounds, "opt 4");

 

UPD.

Works for the active layer. For an arbitrary layer, it requires modification.

 

2 replies

Legend
May 3, 2021

Try this

 

var r = new ActionReference();
var d = new ActionDescriptor();

r.putProperty(stringIDToTypeID("property"), stringIDToTypeID("json"));
r.putEnumerated(stringIDToTypeID("document"), stringIDToTypeID("ordinal"), stringIDToTypeID("targetEnum"));
d.putReference(stringIDToTypeID("null"), r);

d.putBoolean(stringIDToTypeID("imageInfo"), false); 
d.putBoolean(stringIDToTypeID( "includeAncestors" ), false);
d.putInteger(stringIDToTypeID("layerID"), app.activeDocument.activeLayer.id);

eval("var o="+executeAction(stringIDToTypeID("get"), d, DialogModes.NO).getString(stringIDToTypeID("json")));

alert(o.layers[0].bounds.left  + ", " + o.layers[0].bounds.top + ", " + o.layers[0].bounds.right + ", " + o.layers[0].bounds.bottom);

upd.

In your case, you can replace

app.activeDocument.activeLayer.id

to

app.activeDocument.layers[0].id

 

 

JJMack
Community Expert
Community Expert
May 3, 2021

R-Bin your knowledge of Action Manager coding and JavaScript is outstanding.  Thank you for helping this forum out. You code does seem to  return to Frame Layer Set bounds.  The only thing in you script I understood is: app.activeDocument.activeLayer.id   the Frame layer needed to be Photoshop current target before running the script. For some reason though my top letf  Y  is 2 pixels off of yours ?

OK I see where the difference is its a strange layer for sure.

JJMack
Innotex Nico Tanne
Inspiring
May 4, 2021

In general, some kind of dregs.

My script shows values depending on what is active, smart object or frame group. Also, I do not know what the author of the topic wants to get.

 

In my script you need to write like this

d.putInteger (stringIDToTypeID ("layerID"), app.activeDocument.layerSets [0].id);

 

 

P.S. If something is wrong then this is a google translator  ))

 


Hello and thank you already for your help!
I do not really understand the whole thing yet 😞
My plan was to create several frames, insert images and put the name of the image under the frame at the end. Somehow I do not get the correct values of the currently selected frame? I have several frames but always get the same value and I must have the frames in a group, otherwise I get 0 as value?

 

what am I doing wrong?

Innotex Nico Tanne
Inspiring
May 3, 2021

Is there no easy way to get bounds of a frame?

hope you can help me i'm not really good in scripting.

Thanks for help

War Unicorn
Community Expert
Community Expert
May 3, 2021

Does this help any?

 

Photoshop script - How to get the bounds of the visible portion of a layer set (group)?

 

(Relatedly, did you post your question over there? Those guys are massive code propellerheads.)