10 Replies Latest reply on Mar 4, 2017 3:55 PM by Andymc7

    Load Group As A Selection?

    Andymc7 Level 1

      Howdy everyone,

       

      So I work with groups. A lot. And I just was thinking how totally kool (and helpful, of course) it would be to Ctrl+click them to a selection, a la a regular layer or smart object. Is this something scriptable?

       

      Many many thanks in advance,

       

      -Andy

        • 1. Re: Load Group As A Selection?
          Andymc7 Level 1

          Wow, I can't believe it's been this long ago that I posted this. No ideas anyone??

          • 2. Re: Load Group As A Selection?
            Chuck Uebele Adobe Community Professional & MVP

            You can put in a feature request or you can try this script, with might run a bit slow, depending on how many layers you have. Just make sure you have the group selected before you run the script.

             

            #target photoshop
            var doc = activeDocument;
            var gp = doc.activeLayer
            getLayers (gp)
            function getLayers(gp1){
                for(var i=0;i<gp1.layers.length;i++){
                    doc.activeLayer = gp1.layers[i];
                    if(gp1.layers[i].typename =='LayerSet'){getLayers (gp1.layers[i])}
                    else{
                        try{
                            sel ()
                            }
                        catch(e){}
                        }
                    }
                doc.activeLayer = gp
                }
            
            function sel(){
                var idAddT = charIDToTypeID( "AddT" );
                    var desc8 = new ActionDescriptor();
                    var idnull = charIDToTypeID( "null" );
                        var ref9 = new ActionReference();
                        var idChnl = charIDToTypeID( "Chnl" );
                        var idfsel = charIDToTypeID( "fsel" );
                        ref9.putProperty( idChnl, idfsel );
                    desc8.putReference( idnull, ref9 );
                    var idT = charIDToTypeID( "T   " );
                        var ref10 = new ActionReference();
                        var idPath = charIDToTypeID( "Path" );
                        var idPath = charIDToTypeID( "Path" );
                        var idvectorMask = stringIDToTypeID( "vectorMask" );
                        ref10.putEnumerated( idPath, idPath, idvectorMask );
                        var idLyr = charIDToTypeID( "Lyr " );
                        var idOrdn = charIDToTypeID( "Ordn" );
                        var idTrgt = charIDToTypeID( "Trgt" );
                        ref10.putEnumerated( idLyr, idOrdn, idTrgt );
                    desc8.putReference( idT, ref10 );
                    var idVrsn = charIDToTypeID( "Vrsn" );
                    desc8.putInteger( idVrsn, 1 );
                    var idvectorMaskParams = stringIDToTypeID( "vectorMaskParams" );
                    desc8.putBoolean( idvectorMaskParams, true );
                executeAction( idAddT, desc8, DialogModes.NO );
                }
            
            1 person found this helpful
            • 3. Re: Load Group As A Selection?
              Andymc7 Level 1

              Hi Chuck,

               

              Thanks so much for your reply. However, I tried running the script with a group selected and nothing happened. I tried selecting the layers within the group, and selecting the group plus the layers, still nothing. So, not sure where the issue is.

               

              Still thanks again for the response.

               

               

              -Andy

              • 4. Re: Load Group As A Selection?
                Chuck Uebele Adobe Community Professional & MVP

                What version of PS and OS are you using?

                • 5. Re: Load Group As A Selection?
                  Andymc7 Level 1

                  Oh, I apologize,

                   

                  I'm on CC 2017, Windows 10

                  • 6. Re: Load Group As A Selection?
                    Chuck Uebele Adobe Community Professional & MVP

                    That's odd. That's what I'm using, and it works. Can you post a screen shot showing your layer panel?

                    • 7. Re: Load Group As A Selection?
                      Chuck Uebele Adobe Community Professional & MVP

                      I ran some more test, and there are issues with different types of layers. Will have to see about fixing it.

                      • 8. Re: Load Group As A Selection?
                        Chuck Uebele Adobe Community Professional & MVP

                        Ok, try this one:

                        #target photoshop
                        var doc = activeDocument;
                        var gp = doc.activeLayer
                        var bound = false
                        var curLayer
                        getLayers (gp)
                        function getLayers(gp1){
                            for(var i=0;i<gp1.layers.length;i++){
                                try{
                                    var check = doc.selection.bounds
                                    bound =true;
                                    }
                                catch(e){bound = false}
                                doc.activeLayer = curLayer = gp1.layers[i];
                                if(curLayer.typename =='LayerSet'){getLayers (gp1.layers[i])}
                                else{
                                        if(curLayer.kind == 'LayerKind.NORMAL'){
                                            if(bound){selPx ()}
                                            else{selPxFirst ()};
                                            }
                                        else{
                                            try{
                                                if(bound){selShape ()}
                                                else{selShapeFirst ()};
                                                }
                                            catch(e){}       
                                            }                
                                    }
                                }
                            doc.activeLayer = gp
                            }//end function
                        
                        function selPxFirst(){
                            var idsetd = charIDToTypeID( "setd" );
                                var desc7 = new ActionDescriptor();
                                var idnull = charIDToTypeID( "null" );
                                    var ref7 = new ActionReference();
                                    var idChnl = charIDToTypeID( "Chnl" );
                                    var idfsel = charIDToTypeID( "fsel" );
                                    ref7.putProperty( idChnl, idfsel );
                                desc7.putReference( idnull, ref7 );
                                var idT = charIDToTypeID( "T   " );
                                    var ref8 = new ActionReference();
                                    var idChnl = charIDToTypeID( "Chnl" );
                                    var idChnl = charIDToTypeID( "Chnl" );
                                    var idTrsp = charIDToTypeID( "Trsp" );
                                    ref8.putEnumerated( idChnl, idChnl, idTrsp );
                                desc7.putReference( idT, ref8 );
                            executeAction( idsetd, desc7, DialogModes.NO );
                            }
                        function selPx(){
                            var idAdd = charIDToTypeID( "Add " );
                                var desc5 = new ActionDescriptor();
                                var idnull = charIDToTypeID( "null" );
                                    var ref5 = new ActionReference();
                                    var idChnl = charIDToTypeID( "Chnl" );
                                    var idChnl = charIDToTypeID( "Chnl" );
                                    var idTrsp = charIDToTypeID( "Trsp" );
                                    ref5.putEnumerated( idChnl, idChnl, idTrsp );
                                desc5.putReference( idnull, ref5 );
                                var idT = charIDToTypeID( "T   " );
                                    var ref6 = new ActionReference();
                                    var idChnl = charIDToTypeID( "Chnl" );
                                    var idfsel = charIDToTypeID( "fsel" );
                                    ref6.putProperty( idChnl, idfsel );
                                desc5.putReference( idT, ref6 );
                            executeAction( idAdd, desc5, DialogModes.NO );
                        }
                        
                        function selShapeFirst(){
                            var idsetd = charIDToTypeID( "setd" );
                                var desc2 = new ActionDescriptor();
                                var idnull = charIDToTypeID( "null" );
                                    var ref1 = new ActionReference();
                                    var idChnl = charIDToTypeID( "Chnl" );
                                    var idfsel = charIDToTypeID( "fsel" );
                                    ref1.putProperty( idChnl, idfsel );
                                desc2.putReference( idnull, ref1 );
                                var idT = charIDToTypeID( "T   " );
                                    var ref2 = new ActionReference();
                                    var idPath = charIDToTypeID( "Path" );
                                    var idPath = charIDToTypeID( "Path" );
                                    var idvectorMask = stringIDToTypeID( "vectorMask" );
                                    ref2.putEnumerated( idPath, idPath, idvectorMask );
                                    var idLyr = charIDToTypeID( "Lyr " );
                                    var idOrdn = charIDToTypeID( "Ordn" );
                                    var idTrgt = charIDToTypeID( "Trgt" );
                                    ref2.putEnumerated( idLyr, idOrdn, idTrgt );
                                desc2.putReference( idT, ref2 );
                                var idVrsn = charIDToTypeID( "Vrsn" );
                                desc2.putInteger( idVrsn, 1 );
                                var idvectorMaskParams = stringIDToTypeID( "vectorMaskParams" );
                                desc2.putBoolean( idvectorMaskParams, true );
                            executeAction( idsetd, desc2, DialogModes.NO );
                            }
                        
                        function selShape(){
                            var idAddT = charIDToTypeID( "AddT" );
                                var desc13 = new ActionDescriptor();
                                var idnull = charIDToTypeID( "null" );
                                    var ref14 = new ActionReference();
                                    var idChnl = charIDToTypeID( "Chnl" );
                                    var idfsel = charIDToTypeID( "fsel" );
                                    ref14.putProperty( idChnl, idfsel );
                                desc13.putReference( idnull, ref14 );
                                var idT = charIDToTypeID( "T   " );
                                    var ref15 = new ActionReference();
                                    var idPath = charIDToTypeID( "Path" );
                                    var idPath = charIDToTypeID( "Path" );
                                    var idvectorMask = stringIDToTypeID( "vectorMask" );
                                    ref15.putEnumerated( idPath, idPath, idvectorMask );
                                    var idLyr = charIDToTypeID( "Lyr " );
                                    var idOrdn = charIDToTypeID( "Ordn" );
                                    var idTrgt = charIDToTypeID( "Trgt" );
                                    ref15.putEnumerated( idLyr, idOrdn, idTrgt );
                                desc13.putReference( idT, ref15 );
                                var idVrsn = charIDToTypeID( "Vrsn" );
                                desc13.putInteger( idVrsn, 1 );
                                var idvectorMaskParams = stringIDToTypeID( "vectorMaskParams" );
                                desc13.putBoolean( idvectorMaskParams, true );
                            executeAction( idAddT, desc13, DialogModes.NO );
                            }
                        
                        2 people found this helpful
                        • 9. Re: Load Group As A Selection?
                          Andymc7 Level 1

                          Hi Chuck,

                           

                          Sorry for just now replying.. crazy day.. anyway, thanks for posting the new script. I'll give it a try!

                           

                           

                          -Andy

                          • 10. Re: Load Group As A Selection?
                            Andymc7 Level 1

                            It works!! Thanks so much!