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

Coordinates from a frame

  • May 3, 2021
  • 2 replies
  • 3610 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
Legend
May 3, 2021

JJMack, I don’t work with new Photoshops, especially with the Frame tool. Please give me your PSD file, I'll see what's wrong with you.

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.)