# How To Expand A Group

**URL:** <https://forums.creativeclouddeveloper.com/t/how-to-expand-a-group/2565>\
**Category:** UXP Plugin API\
**Created:** [February 21, 2021, 10:17pm UTC](https://forums.creativeclouddeveloper.com/t/how-to-expand-a-group/2565 "2021-02-21T22:17:48Z")\
**Posts on this page:** 1\
**Showing post:** 7

<div class="post-metadata">

**Author:** ![Joe](https://sea1.discourse-cdn.com/flex015/user_avatar/forums.creativeclouddeveloper.com/joe/32/1246_2.png) [@Joe](https://forums.creativeclouddeveloper.com/u/Joe)\
**Post date:** [March 10, 2021, 2:04pm UTC](https://forums.creativeclouddeveloper.com/t/how-to-expand-a-group/2565/7 "2021-03-10T14:04:58Z")

</div>

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"},
                            {
                                _ref: "layer",
                                _enum: "ordinal",
                                _value: "targetEnum",
                            }
                        ],
                    },
                    to: expand,
                    recursive,
                    _options: {dialogOptions: "dontDisplay"},
                },
            ],
            {synchronousExecution: true}
        );
    } catch (e) {
        console.error(e.message);
    }
}

```

I hope this helps

---

_[View the full topic](https://forums.creativeclouddeveloper.com/t/how-to-expand-a-group/2565)._
