14 Replies Latest reply on Feb 7, 2015 9:12 AM by c.pfaffenbichler

    Move group into another group

    Beracah SB Level 1

      Hi all,

       

      Can any one help to create a script to move the group named "Shine" into another group named "Shine All".

      Thanks in advance.

       

      Snapshot show for better understanding.

      set.jpg

        • 1. Re: Move group into another group
          c.pfaffenbichler Level 9

          Does this help?

          // move groups of a certain name into group of a certain name;
          // 2015, use it at your own risk;
          #target "photoshop-70.032"
          if (app.documents.length > 0) {
          var myDocument = app.activeDocument;
          var name1 = "Shine";
          var targetName = "Shine All";
          var targetGroup = layersWithName (targetName);
          // if exactly one group qualifies;
          if (targetGroup.length == 1) {
          // collect groups;
          var theGroups = layersWithName(name1);
          // process groups;
          for (var m = theGroups.length - 1; m >= 0; m--) {
            moveTo(theGroups[m][1], targetGroup[0][1]);
            };
          }
          else {alert ("too many or too few groups called »"+targetName+"«")}
          };
          ////////////////////////////////////
          function layersWithName (thisName) {
          // the file;
          var myDocument = app.activeDocument;
          // get number of layers;
          var ref = new ActionReference();
          ref.putEnumerated( charIDToTypeID("Dcmn"), charIDToTypeID("Ordn"), charIDToTypeID("Trgt") );
          var applicationDesc = executeActionGet(ref);
          var theNumber = applicationDesc.getInteger(stringIDToTypeID("numberOfLayers"));
          // process the layers;
          var theLayers = new Array;
          for (var m = 0; m <= theNumber; m++) {
          try {
          var ref = new ActionReference();
          ref.putIndex( charIDToTypeID( "Lyr " ), m);
          var layerDesc = executeActionGet(ref);
          var layerSet = typeIDToStringID(layerDesc.getEnumerationValue(stringIDToTypeID("layerSection")));
          var isBackground = layerDesc.getBoolean(stringIDToTypeID("background"));
          // if not layer group collect values;
          if (layerSet != "layerSectionEnd" /*&& layerSet != "layerSectionStart"*/ && isBackground != true) {
          var theName = layerDesc.getString(stringIDToTypeID('name'));
          var theID = layerDesc.getInteger(stringIDToTypeID('layerID'));
          if (theName == thisName) {
          theLayers.push([theName, theID)
          }
          };
          }
          catch (e) {};
          };
          return (theLayers)
          };
          ////// move //////
          function moveTo (theLayer, theGroup) {
          // get index;
          var ref = new ActionReference();
          ref.putIdentifier( charIDToTypeID( "Lyr " ), theGroup - 1);
          var layerDesc = executeActionGet(ref);
          var theIndex = layerDesc.getInteger(stringIDToTypeID("itemIndex"));
          // =======================================================
          var idmove = charIDToTypeID( "move" );
              var desc5 = new ActionDescriptor();
              var idnull = charIDToTypeID( "null" );
                  var ref4 = new ActionReference();
                  var idLyr = charIDToTypeID( "Lyr " );
                  ref4.putIdentifier( idLyr, theLayer );
              desc5.putReference( idnull, ref4 );
              var idT = charIDToTypeID( "T  " );
                  var ref5 = new ActionReference();
                  var idLyr = charIDToTypeID( "Lyr " );
                  ref5.putIndex( idLyr, theIndex );
              desc5.putReference( idT, ref5 );
              var idAdjs = charIDToTypeID( "Adjs" );
              desc5.putBoolean( idAdjs, false );
              var idVrsn = charIDToTypeID( "Vrsn" );
              desc5.putInteger( idVrsn, 5 );
          executeAction( idmove, desc5, DialogModes.NO );
          };
          
          

           

          edited

          • 2. Re: Move group into another group
            Beracah SB Level 1

            Thank you pfaffen,

             

            I am using CS6, I got a error message @the line 66, it would be great if you could fix this. plz see the screen grab below.

            Screen shot 2015-02-05 at 7.09.01 PM.png

            • 3. Re: Move group into another group
              c.pfaffenbichler Level 9

              I can’t reproduce the issue, can you post the (downsampled) file in which the behaviour occurs?

              • 4. Re: Move group into another group
                c.pfaffenbichler Level 9

                Ah, it seems the text has been "corrected" when I posted it – there need to be three spaces after the "T" in that line.

                • 5. Re: Move group into another group
                  pixxxel schubser MVP & Adobe Community Professional

                  Hi together,

                  try to use this line (with three spaces after T):

                      var idT = charIDToTypeID( "T   " ); 
                  
                  

                   

                  instead of this line:

                      var idT = charIDToTypeID( "T  " );  
                  
                  
                  • 6. Re: Move group into another group
                    Beracah SB Level 1

                    Hi,

                     

                    Thank you for the effort, it's working!!! however all the group named "Shine" and moving below the "Shine All" group, but I need all the group named "Shine" needs to move inside "Shine All" group.

                     

                    Can you plz fix this for me?

                    Untitled-1.jpg

                    • 7. Re: Move group into another group
                      c.pfaffenbichler Level 9

                      That’s what I get, so I can’t reproduce that behaviour.

                      shineTestScr.jpg

                      • 8. Re: Move group into another group
                        Beracah SB Level 1

                        Okay, Thanks for your try

                        • 9. Re: Move group into another group
                          c.pfaffenbichler Level 9

                          Can you post the (downsampled) file in which the behaviour occurs?

                          • 10. Re: Move group into another group
                            Beracah SB Level 1

                            Is that possible to sent the psd files through forum?

                            I don't know how to upload sample files, however I have created a sample file and shown the screengrab below.

                            Shine.jpg

                            • 11. Re: Move group into another group
                              c.pfaffenbichler Level 9

                              I suspect I got the correct results by accident (in connection with the layer in the Group) – I am not sure when I will have time to look into this further.

                              • 12. Re: Move group into another group
                                c.pfaffenbichler Level 9

                                Please try replacing the function moveTo with

                                ////// move //////

                                function moveTo (theLayer, theGroup) {

                                // get index;

                                var ref = new ActionReference();

                                ref.putIdentifier( charIDToTypeID( "Lyr " ), theGroup );

                                var layerDesc = executeActionGet(ref);

                                var theIndex = layerDesc.getInteger(stringIDToTypeID("itemIndex"));

                                // =======================================================

                                var idmove = charIDToTypeID( "move" );

                                    var desc5 = new ActionDescriptor();

                                    var idnull = charIDToTypeID( "null" );

                                        var ref4 = new ActionReference();

                                        var idLyr = charIDToTypeID( "Lyr " );

                                        ref4.putIdentifier( idLyr, theLayer );

                                    desc5.putReference( idnull, ref4 );

                                    var idT = charIDToTypeID( "T   " );

                                        var ref5 = new ActionReference();

                                        var idLyr = charIDToTypeID( "Lyr " );

                                        ref5.putIndex( idLyr, theIndex - 1 );

                                    desc5.putReference( idT, ref5 );

                                    var idAdjs = charIDToTypeID( "Adjs" );

                                    desc5.putBoolean( idAdjs, false );

                                    var idVrsn = charIDToTypeID( "Vrsn" );

                                    desc5.putInteger( idVrsn, 5 );

                                executeAction( idmove, desc5, DialogModes.NO );

                                };

                                Does this work?

                                 

                                Edit: A check should probably be added to make sure the target Group does not reside within one of the affected Groups.

                                • 13. Re: Move group into another group
                                  Beracah SB Level 1

                                  pf,

                                   

                                  It's working great, thanks for your help

                                  • 14. Re: Move group into another group
                                    c.pfaffenbichler Level 9

                                    Sorry I missed the problem originally.

                                    I guess I should test Scripts on more than one file in the future, because with only one file a Script might work by accident …