# How to tell if layer has an existing frame (frame tool)

**URL:** https://forums.creativeclouddeveloper.com/t/how-to-tell-if-layer-has-an-existing-frame-frame-tool/5586
**Category:** Photoshop
**Tags:** javascript, batch-play
**Created:** [December 13, 2022, 7:00pm UTC](https://forums.creativeclouddeveloper.com/t/how-to-tell-if-layer-has-an-existing-frame-frame-tool/5586 "2022-12-13T19:00:19Z")
**Posts on this page:** 3
**Page:** 1

<div class="post-metadata">

### Author: ![contactzero](https://avatars.discourse-cdn.com/v4/letter/c/9f8e36/32.png) [@contactzero](https://forums.creativeclouddeveloper.com/u/contactzero)
#### Post date: [December 13, 2022, 7:00pm UTC](https://forums.creativeclouddeveloper.com/t/how-to-tell-if-layer-has-an-existing-frame-frame-tool/5586/1 "2022-12-13T19:00:19Z")

</div>

I add a frame to a layer via BATCHPLAY if the layer initially does not have one – this I have.

Now, I want to test if the layer ALREADY has a frame… I am at a loss.

Can someone point me in then right direction?

TIA

---

<div class="post-metadata">

### Author: ![DavideBarranca](https://sea1.discourse-cdn.com/flex015/user_avatar/forums.creativeclouddeveloper.com/davidebarranca/32/1523_2.png) [@DavideBarranca](https://forums.creativeclouddeveloper.com/u/DavideBarranca)
#### Post date: [December 13, 2022, 7:50pm UTC](https://forums.creativeclouddeveloper.com/t/how-to-tell-if-layer-has-an-existing-frame-frame-tool/5586/2 "2022-12-13T19:50:58Z")

</div>

Hi,  
try this:

```javascript
await executeAsModal(async () => {
    let res = await batchPlay([
        {
            _obj: "get",

            _target: [
               { _property: "framedGroup"},
               {
                  _ref: "layer",
                  _enum: "ordinal",
                  _value: "targetEnum"
               },
            ]
         }
    ], {})
    if (res[0].hasOwnProperty("framedGroup")) {
        // The active layer has a frame
        console.log("A Frame is here")
    } else {
        // No frame
        console.log("Nope")
    }
}, { commandName: "whatever" })

```

HTH,

Davide

---

<div class="post-metadata">

### Author: ![contactzero](https://avatars.discourse-cdn.com/v4/letter/c/9f8e36/32.png) [@contactzero](https://forums.creativeclouddeveloper.com/u/contactzero)
#### Post date: [December 14, 2022, 11:54am UTC](https://forums.creativeclouddeveloper.com/t/how-to-tell-if-layer-has-an-existing-frame-frame-tool/5586/3 "2022-12-14T11:54:58Z")

</div>

Genius Davide – as always… thank you!

For others following this…  
Here is a button I created to make a frame with a border width of 3 cm on an image layer.

I will modify the id and use class instead and pass a variable width so that the code stays more streamlined.

```auto
   document
   .getElementById("btnbw3")
   .addEventListener("click", async function () {

    borderwidth = Math.round(3*300/2.54); //cm

    

    frameLeft = borderwidth;
    frameTop = borderwidth;
    frameRight = app.activeDocument.width-borderwidth;
    frameBottom = app.activeDocument.height-borderwidth;
        console.log("Click 3 - Create a frame with a 3cm border");
        console.log(`borderwidth: ${borderwidth}`);
        console.log(`left: ${frameLeft}`);
        console.log(`top: ${frameTop}`);
        console.log(`right: ${frameRight}`);
        console.log(`bottom: ${frameBottom}`);

        var res=[];
        await core.executeAsModal(async () => {
         await batchPlay([
          //Select backmost layer  
          {"_obj":"select","_target":[{"_enum":"ordinal","_ref":"layer","_value":"back"}],"makeVisible":false},
          //Select forward layer
          {"_obj":"select","_target":[{"_enum":"ordinal","_ref":"layer","_value":"forwardEnum"}],"makeVisible":false},
          //Select forward layer
          {"_obj":"select","_target":[{"_enum":"ordinal","_ref":"layer","_value":"forwardEnum"}],"makeVisible":false},
            ], {})
          });
     

        await core.executeAsModal(async () => {
          let res = await batchPlay([
              {_obj: "get",_target: [{ _property: "framedGroup"},{_ref: "layer",_enum: "ordinal",_value: "targetEnum"},]},
            ], {})

          if (res[0].hasOwnProperty("framedGroup")) {
              // The active layer has a frame
              await core.executeAsModal(async () => {
                await batchPlay([
                  // Ungroup Layers current layer OR REMOVE FRAME FROM LAYER...
                  {"_obj":"ungroupLayersEvent","_target":[{"_enum":"ordinal","_ref":"layer","_value":"targetEnum"}]},
                  // Set Selection to None
                  {"_obj":"set","_target":[{"_property":"selection","_ref":"channel"}],"to":{"_enum":"ordinal","_value":"none"}},
                 // Make NEW FRAME
                 {"LockPPI":false,"PreferredResolution":300.0,"SavedIteratedName":"","_obj":"make","_target":[{"_ref":"framedGroupSection"}],"framedGroupRect":{"_obj":"classFloatRect","bottom":frameBottom,"left":frameLeft,"right":frameRight,"top":frameTop},},
                ], {})
                });
              console.log("layer has frame...")

                } else {
                      // No frame
                      await core.executeAsModal(async () => {
                        await batchPlay([
                 // Make NEW FRAME
                 {"LockPPI":false,"PreferredResolution":300.0,"SavedIteratedName":"","_obj":"make","_target":[{"_ref":"framedGroupSection"}],"framedGroupRect":{"_obj":"classFloatRect","bottom":frameBottom,"left":frameLeft,"right":frameRight,"top":frameTop},},
                      ], {})
                      });
                    console.log("layer has no frame.")
                }
              });

                // }, { commandName: "whatever" })
              

        //^^^^^^^^^^^^^
      });

```

Note: My particular case always has the image layer 3rd from the bottom. You could select by name I suppose…
