Skip to main content
Inspiring
February 3, 2025
Answered

check if a group is open or closed

  • February 3, 2025
  • 3 replies
  • 1234 views

I have a small problem
I need to know if a group is open or closed
I put up a small script in uxp
but it tells me that the group is always open even if it is closed,
this is the script.

 

checkLayerGroupStatus()

async function checkLayerGroupStatus() {
    const layers = app.activeDocument.layers;
    const groupName = "Color"; 

    const layerGroup = layers.find(layer => layer.name === groupName && layer.layers);
    if (!layerGroup) {
        showAlert( `Level group "${groupName}" not found`);
        return;
    }

    const isOpen = layerGroup.visible;
    if (isOpen) {
        showAlert(`The level group "${groupName}" is open.`);
    } else {
        showAlert( `Level group "${groupName}" is closed.`);
    }
}
Correct answer sttk3

Dang again! 

As the property worked fine in ESTK Scripting I assumed the UXP samples @sttk3 linked to would work out for you. 


Verified that it works with this UXP script.

3 replies

Legend
February 3, 2025

It seems that layerSectionExpanded is the property being sought. Get it via batchPlay.

Legend
February 4, 2025

Found also an ExtendScript version.

c.pfaffenbichler
Community Expert
Community Expert
February 4, 2025

Dang, fully missed that one! 

c.pfaffenbichler
Community Expert
Community Expert
February 3, 2025

@DBarranca , please forgive the intrusion. 

Do you know whether in UXP Scripting Groups have a property that indicates whether they are closed or expanded in the Layers Panel? 

Inspiring
February 3, 2025

I haven't found anything about it, I hope Barranca passes by this post.

c.pfaffenbichler
Community Expert
Community Expert
February 3, 2025

Is »visible« not the Layer Visibility which is unrelated to whether a Group is open or not? 

Inspiring
February 3, 2025

even if I remove visible the problem remains.

c.pfaffenbichler
Community Expert
Community Expert
February 3, 2025

Not what I meant. 

 

»visible« seems to refer to the Layer’s/Group’s visibility, so where is the property that describes whether a Group is expanded?