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

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

1 Like

Hi,
try this:

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

2 Likes

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.

   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…

1 Like