3 Replies Latest reply on Feb 2, 2012 1:46 PM by Paul Riggott

    Expand/Contract groups

    dgolberg Level 1

      Kind of an odd request here, but is there a way to have a script expand or shrink a layer group in layers window?  I noticed script listener doesn't seem to output anything relating to this, so I thought I'd see if anyone here knew of a way to do it (if it's even supported in scripting).  Thanks for any input!

       

      dgolberg

        • 2. Re: Expand/Contract groups
          dgolberg Level 1

          Thanks for the link Paul.  I looked at the link, but found that to be FAR more code than I was interested in using.  It got me to thinking though, and I cam up with a far simpler method of collapsing a group; just recreate it!  See code below:

          #target photoshop

          var myDoc = app.activeDocument;

           

          var layerName = myDoc.activeLayer.name;

          unGroup();

          group();

          myDoc.activeLayer.name = layerName;

           

          function unGroup() {

              var idungroupLayersEvent = stringIDToTypeID( "ungroupLayersEvent" );

              var desc2 = new ActionDescriptor();

              var idnull = charIDToTypeID( "null" );

                  var ref1 = new ActionReference();

                  var idLyr = charIDToTypeID( "Lyr " );

                  var idOrdn = charIDToTypeID( "Ordn" );

                  var idTrgt = charIDToTypeID( "Trgt" );

                  ref1.putEnumerated( idLyr, idOrdn, idTrgt );

              desc2.putReference( idnull, ref1 );

              executeAction( idungroupLayersEvent, desc2, DialogModes.NO );

          }

           

          function group() {

              var idMk = charIDToTypeID( "Mk  " );

                  var desc3 = new ActionDescriptor();

                  var idnull = charIDToTypeID( "null" );

                      var ref2 = new ActionReference();

                      var idlayerSection = stringIDToTypeID( "layerSection" );

                      ref2.putClass( idlayerSection );

                  desc3.putReference( idnull, ref2 );

                  var idFrom = charIDToTypeID( "From" );

                      var ref3 = new ActionReference();

                      var idLyr = charIDToTypeID( "Lyr " );

                      var idOrdn = charIDToTypeID( "Ordn" );

                      var idTrgt = charIDToTypeID( "Trgt" );

                      ref3.putEnumerated( idLyr, idOrdn, idTrgt );

                  desc3.putReference( idFrom, ref3 );

              executeAction( idMk, desc3, DialogModes.NO );

          }

          I'm not sure if there are commands setup for grouping/ungrouping, so I just used the scriptListener code.  If they do have more simplified commands for these, please; let me know!

           

          Note: This will destroy any layer masks on the immediate group being collapsed (sub-groups are unaffected unless the method is applied directly to them).

          • 3. Re: Expand/Contract groups
            Paul Riggott Level 6

            You might want to add opacity for the group, but if you know what the state of your psd's are, your code should be fine.