# Get all clipped layers from the base layer?

**URL:** <https://forums.creativeclouddeveloper.com/t/get-all-clipped-layers-from-the-base-layer/5088>\
**Category:** Photoshop\
**Created:** [August 13, 2022, 7:00pm UTC](https://forums.creativeclouddeveloper.com/t/get-all-clipped-layers-from-the-base-layer/5088 "2022-08-13T19:00:05Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![bbogdan](https://sea1.discourse-cdn.com/flex015/user_avatar/forums.creativeclouddeveloper.com/bbogdan/32/2272_2.png) [@bbogdan](https://forums.creativeclouddeveloper.com/u/bbogdan)\
**Post date:** [August 13, 2022, 7:00pm UTC](https://forums.creativeclouddeveloper.com/t/get-all-clipped-layers-from-the-base-layer/5088/1 "2022-08-13T19:00:05Z")

</div>

Is there an elegant way to get all clipped layers from the selected layer?  
Look at the following image:

 ![image](https://us1.discourse-cdn.com/flex015/uploads/xdplugins/original/2X/d/dff1f3b39f4f7f28394676b1ed43a67d1b0c3279.png)

If I select the base layer, in this case, “Layer 1”, how can I get all the layers that are clipped to it? I tried to use the `batchPlay` to make a group but then I saw that it requires a `layerSectionStart` and end.  
In the end, I would like to perform some operations on the base layer which can involve losing all clipped layers, and then I would like to clip them all back to the selected layer.

---

<div class="post-metadata">

**Author:** ![bbogdan](https://sea1.discourse-cdn.com/flex015/user_avatar/forums.creativeclouddeveloper.com/bbogdan/32/2272_2.png) [@bbogdan](https://forums.creativeclouddeveloper.com/u/bbogdan)\
**Post date:** [August 13, 2022, 7:29pm UTC](https://forums.creativeclouddeveloper.com/t/get-all-clipped-layers-from-the-base-layer/5088/2 "2022-08-13T19:29:45Z")

</div>

It would be great if the DOM supported this, so we could write something like `layer.clippedLayers` to get the array of clipped layers. (similar to `layer.linkedLayers`). In the ExtendScript I got those by performing several operations:

1. Make a group
2. Loop the group and get all layers that are clipped from the group (store them into an array)
3. Ungroup

and then after the operations are complete clip them back to the layer:

1. select a layer by id from the array
2. clip the layer down

---

<div class="post-metadata">

**Author:** ![bbogdan](https://sea1.discourse-cdn.com/flex015/user_avatar/forums.creativeclouddeveloper.com/bbogdan/32/2272_2.png) [@bbogdan](https://forums.creativeclouddeveloper.com/u/bbogdan)\
**Post date:** [August 14, 2022, 6:10pm UTC](https://forums.creativeclouddeveloper.com/t/get-all-clipped-layers-from-the-base-layer/5088/3 "2022-08-14T18:10:04Z")

</div>

Never mind I found a solution. This one returns the array of clipped layers from the selected layer:

```auto
import { app } from "photoshop";
import { Layer } from "photoshop/dom/Layer";

export const getAllClippedLayers = (selectedLayer: Layer) => {
  // Layer parent:
  // 1. group (if the layer is located inside the group)
  // 2. document
  const layerParent = selectedLayer.parent
    ? selectedLayer.parent
    : app.activeDocument;
  return layerParent.layers.filter((layer) => layer.isClippingMask);
};

```

At the very end of the operation if there are for example two selected layers located inside the same group, and they both have some clipped layers to them, then that array would need to be filtered again to remove the duplicates and leave only the unique values with only the layers that need to be clipped back. Something like this:

```auto
const layersToClipBack = allClippedLayers.filter(
    (layer, index, self) =>
      self.findIndex((item) => item.id === layer.id) === index && !layer.isClippingMask
  );

```

---

<div class="post-metadata">

**Author:** ![Jarda](https://sea1.discourse-cdn.com/flex015/user_avatar/forums.creativeclouddeveloper.com/jarda/32/1909_2.png) [@Jarda](https://forums.creativeclouddeveloper.com/u/Jarda)\
**Post date:** [August 15, 2022, 5:56pm UTC](https://forums.creativeclouddeveloper.com/t/get-all-clipped-layers-from-the-base-layer/5088/4 "2022-08-15T17:56:45Z")

</div>

This is one of the things that I would really like to see in DOM. Since clipped layers are very common but getting its array is unnecessarily complicated.

---

<div class="post-metadata">

**Author:** ![bbogdan](https://sea1.discourse-cdn.com/flex015/user_avatar/forums.creativeclouddeveloper.com/bbogdan/32/2272_2.png) [@bbogdan](https://forums.creativeclouddeveloper.com/u/bbogdan)\
**Post date:** [August 15, 2022, 6:24pm UTC](https://forums.creativeclouddeveloper.com/t/get-all-clipped-layers-from-the-base-layer/5088/5 "2022-08-15T18:24:35Z")

</div>

This is the solution I came up with using what’s available right now, but yes something like `layer.clippedLayers` would be the best. Agree.
