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

Coordinates from a frame

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

 

 

Innotex Nico Tanne
Inspiring
May 6, 2021

Hello r-bin,

Thanks again for your help!
now I just noticed that only the size of the filled object is output as bound. But I need the values of the outer edges of the frame, even if the image in the frame is smaller.
How can I implement this?

r-binCorrect answer
Legend
May 6, 2021

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.

 

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