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

Coordinates from a frame

Contributor ,
May 03, 2021 May 03, 2021

Copy link to clipboard

Copied

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

TOPICS
Actions and scripting

Views

2.9K

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 2 Correct answers

People's Champ , May 03, 2021 May 03, 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("v
...

Votes

Translate

Translate
People's Champ , May 06, 2021 May 06, 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("rig
...

Votes

Translate

Translate
Adobe
Contributor ,
May 03, 2021 May 03, 2021

Copy link to clipboard

Copied

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

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 ,
May 03, 2021 May 03, 2021

Copy link to clipboard

Copied

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

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 ,
May 03, 2021 May 03, 2021

Copy link to clipboard

Copied

If you are using Photoshop Frame tool to create Photoshop  Frame layers. Photoshop Frame Layer are very strange.  That are also not needed.  Photoshop never has a Problem framing images with normal layer masks and vector layer masks. Why Adobe thought they needed an additional Frame mask is beyond me.  I have remove the frame tool from my  Toolbar and disabled it shortcut.   As I wrote its a strange Layer for it is both a Layer Set and a Smart Object Layer so there is a Layer Name and a Layer Set name. In the Layers palette only one name is displayed and the Frame Mask Thumbnail is where the Smart Object Layer content thumbnail should be. The bounds of the Frame Later Set seem to be the bounds of the Frame Mask image area.  But the shape of the image area does not have to be a rectangle it can be an oval, dostorted  etc and be masked additionally with a layer mask.  Becaue Place is used place may scale the image to small the because of imag files Print PPI setting  and the frame tool design does not scale the placed imags up to fill the frame but, you can. The smart object has the original images files pixels.  I just ignore that Adobe Frame tool existance.

Capture.jpg

 

So the Frame's Layer Set bounds may be what your are looking. You do not want the smart object layer bounds that is masked by the Frame Mask.

JJMack

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 ,
May 03, 2021 May 03, 2021

Copy link to clipboard

Copied

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

 

 

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 ,
May 03, 2021 May 03, 2021

Copy link to clipboard

Copied

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 ?

Capture.jpg

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

Capture.jpg

JJMack

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 ,
May 03, 2021 May 03, 2021

Copy link to clipboard

Copied

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.

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 ,
May 03, 2021 May 03, 2021

Copy link to clipboard

Copied

I do not use the Frame tool either. It very  strange thing.  If you look at my Layer stack scripts alert you will see  a frame layer is a Layer set and a smart object layer. Your Script alert  top left  bounds is the smart object layer's top left bounds  and your  Bottom Right Bounds is  Layer Set's Bottom Right bounds.   I created this layer for this thread.  I removed the Frame tool from my toolbar its not needed and IMO has issues. I do not use it at all.

JJMack

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 ,
May 03, 2021 May 03, 2021

Copy link to clipboard

Copied

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

 

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 ,
May 03, 2021 May 03, 2021

Copy link to clipboard

Copied

A Frame Layer is strange it seems to be a layer set and a smart object layer since the frame layer is targeted I guess both the Layer Set and the Smart Object late are the documents active layer though the have different layer ID and Layer Name. A Layer set Object and a Layer Object  seem to be similar objects a layer object.

JJMack

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 ,
May 03, 2021 May 03, 2021

Copy link to clipboard

Copied

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?

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 ,
May 04, 2021 May 04, 2021

Copy link to clipboard

Copied

You may want to look at Collage scripts all the is required in as College template to frame an image is an Alpha Channel that mapse the Image location size and shape. The script will place in your Images as smart object lalayer scale the layer to fill the image location, position the images to their Collage image location and mask the image to shape. The scripts can also stamp the images file manes over the image in one of 9 locations.  Layer Styles can be add to the Image and text layer the scripts adds.  Photoshop has no problem framing images without a frame tool. While all that my Collage template Design requires is a Background Layer and Alpha channels name Image 1, Image 2, ..., Image N. There can be additional layers above the required background layer to add fancy frames around the image areas and have overlay embellishments on the images.  My Scripts Place image in order Above the background layer below the templates other layers and stamp image name by adding text late above the top most late in the template over the Image area.  The limitations is the scripts can not add rotation, perspective distortion warping because I wanted to be able to populate the templates using any size image and have my script scale the smart object layers size.  If you need rotation, warping, perspective distortion you can use my Mockup template populating scripts they updated Smart Object in mockup templates. However, my mockup scripts do not support stamping file on images for the script have no of know how many location a smart object may be use in the templates or how they may be warped and distorted.

 

So a simple two layer  collage template with 5 mapping Image Alpha channels (Photoshop limit is 53 Alpha)  My scripts can populate and stamp 5 names.  Here the Template in photoshop you cabs see how simple it is,  Then one of my collage script dialog. them  the aotomated populate  template.

Capture.jpg

 

My Free Photoshop Photo Collage mockup Toolkit 

 

JJMack

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 ,
May 05, 2021 May 05, 2021

Copy link to clipboard

Copied

Thanks all for your help 🙂
I will also deal with the collage mockup 👍 in any case a great thing 🙂

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 ,
May 05, 2021 May 05, 2021

Copy link to clipboard

Copied

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?

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 ,
May 06, 2021 May 06, 2021

Copy link to clipboard

Copied

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.

 

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 ,
May 06, 2021 May 06, 2021

Copy link to clipboard

Copied

thank you for your effort!
now everything works as it should 🙂

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 ,
May 13, 2021 May 13, 2021

Copy link to clipboard

Copied

That may be the Canvas bonds for all I see in the Layer set and the smart object layer  is the bounds of the visible area.  I would think a Frame mask would hide all, areas  outside the visible ares. The Smart object Image layer could be transformed to be huge. The frame mask would have to hide all of the Image that is over the document canvas outside the frame's visible area.

 

 

Here after creating a Oval Frame Layer and Placing in a Raw Image.  I added black Canvas 200% width and height. I transformed the Placed Image to be huge so just one eye would be in the frme's visible area.   I then moved the frame visible area so it over some of the background layer's black and white areas. The ran my layer stack script here is what I see.

image.png

 

When I created the frame layer the frame thumbnail and image thumbnail and background looked like this: You can see the frames outer bounds is the Canvas bounds

image.png

So the frames layer set bounds is the bounds of the frames visible area.  The Smart Object layers bounds can be any bound the user transform the object to. The Frame's outer bounds is the documents canvas bounds and the frame's visible ares can be positione anywhere. 

image.png

even off canvas.

JJMack

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
Participant ,
Sep 01, 2022 Sep 01, 2022

Copy link to clipboard

Copied

LATEST

Is there anywhere we can find or download this "Layer Stack Script" JJMack mentions that outputs info about all the layers in the document? Thanks.

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