# How to use code to collapse the selected l layer group in uxp?

**URL:** <https://forums.creativeclouddeveloper.com/t/how-to-use-code-to-collapse-the-selected-l-layer-group-in-uxp/2591>\
**Category:** Photoshop\
**Tags:** uxp, javascript\
**Created:** [February 25, 2021, 12:26pm UTC](https://forums.creativeclouddeveloper.com/t/how-to-use-code-to-collapse-the-selected-l-layer-group-in-uxp/2591 "2021-02-25T12:26:11Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![MrL](https://avatars.discourse-cdn.com/v4/letter/m/b487fb/32.png) [@MrL](https://forums.creativeclouddeveloper.com/u/MrL)\
**Post date:** [February 25, 2021, 12:26pm UTC](https://forums.creativeclouddeveloper.com/t/how-to-use-code-to-collapse-the-selected-l-layer-group-in-uxp/2591/1 "2021-02-25T12:26:11Z")

</div>

Hello,  
How to use code to collapse the selected l layer group in uxp?  
I can’t get this function from the API of uxp, but it’s strange that I can get the function of collapsing all groups.

---

<div class="post-metadata">

**Author:** ![Pierre\_G](https://sea1.discourse-cdn.com/flex015/user_avatar/forums.creativeclouddeveloper.com/pierre_g/32/971_2.png) [@Pierre\_G](https://forums.creativeclouddeveloper.com/u/Pierre_G)\
**Post date:** [February 25, 2021, 12:45pm UTC](https://forums.creativeclouddeveloper.com/t/how-to-use-code-to-collapse-the-selected-l-layer-group-in-uxp/2591/2 "2021-02-25T12:45:03Z")

</div>

Collapsing a group with batchPlay can be done using:

```auto
await batchPlay(
[
   // collapse current selected group
      {
        "_obj": "collapseAllGroupsEvent",
        "_isCommand": true,
        "_options": {
          "dialogOptions": "dontDisplay"
        }
      }
],{});

```

> [@How To Expand A Group](http://forums.creativeclouddeveloper.com/t/how-to-expand-a-group/2565/3):
>
> Thanks @Pierre_G that solution worked out great. smiley

---

<div class="post-metadata">

**Author:** ![Zob](https://avatars.discourse-cdn.com/v4/letter/z/87869e/32.png) [@Zob](https://forums.creativeclouddeveloper.com/u/Zob)\
**Post date:** [March 9, 2023, 4:45pm UTC](https://forums.creativeclouddeveloper.com/t/how-to-use-code-to-collapse-the-selected-l-layer-group-in-uxp/2591/3 "2023-03-09T16:45:45Z")

</div>

This is a really great command! It collapses _all_ group layers in the document, which definitely has utility. If a person just needs to collapse or show a single group, that command is located here.  
(I know you know already Pierre, I am including this for easy navigation)

> [@How To Expand A Group](http://forums.creativeclouddeveloper.com/t/how-to-expand-a-group/2565/7):
>
> I have built a function with which you can open and close a group. With the option “recursive” you can say if all subfolders should also be closed or opened. const photoshop = require("photoshop"); const collapseFolder = (expand = false, recursive = false) =\> { try { photoshop.action.batchPlay( [ { \_obj: "set", \_target: { \_ref: [ {\_property: "layerSectionExpanded"…
