Search code examples
javascriptphotoshopphotoshop-script

Is there a way to EXPAND a group in Photoshop?


In the Layers panel, Photoshop has a dropdown option to 'Collapse All Groups'. Is there a reverse option to expand one or all groups or a way to do it in Javascript?


Solution

  • Here you go, answer is derived from

    https://community.adobe.com/t5/photoshop/expand-collapse-a-group-via-javascript/td-p/7286289/page/2?page=1%3F

    var groupname = app.activeDocument.activeLayer.name // name of active layer 
    var idungroupLayersEvent = stringIDToTypeID( "ungroupLayersEvent" ); // ungroup layer event 
    
    var desc14 = new ActionDescriptor();
    
    var idnull = charIDToTypeID( "null" );
    
    var ref13 = new ActionReference();
    
    var idLyr = charIDToTypeID( "Lyr " );
    var idOrdn = charIDToTypeID( "Ordn" );
    var idTrgt = charIDToTypeID( "Trgt" );
    ref13.putEnumerated( idLyr, idOrdn, idTrgt );
    desc14.putReference( idnull, ref13 );
    
    executeAction( idungroupLayersEvent, desc14, DialogModes.NO );
    
    var idMk = charIDToTypeID( "Mk  " ); // make action , note the space
    var desc15 = new ActionDescriptor();
    var idnull = charIDToTypeID( "null" );
    
    var ref14 = new ActionReference();
    
    var idlayerSection = stringIDToTypeID( "layerSection" );
    ref14.putClass( idlayerSection );
    desc15.putReference( idnull, ref14 );
    var idFrom = charIDToTypeID( "From" );
    
    var ref15 = new ActionReference();
    
    var idLyr = charIDToTypeID( "Lyr " ); // <-- note the space
    var idOrdn = charIDToTypeID( "Ordn" );
    var idTrgt = charIDToTypeID( "Trgt" );
    ref15.putEnumerated( idLyr, idOrdn, idTrgt );
    desc15.putReference( idFrom, ref15 );
    
    executeAction( idMk, desc15, DialogModes.NO );
    app.activeDocument.activeLayer.name = groupname // recall group name