4 Replies Latest reply on Nov 18, 2016 5:55 AM by Laubender

    How using Extendscript to direct select items in a group?

    Bill McLean Level 1

      Using extend script I want to direct select objects that are contained within a container (group).  If I select the group, I get this:

       

      DirectSelection-0.png

       

      What I want to have happen is:

       

       

      DirectSelection-2.png

       

      I have the code so far:

       

      {

        var obj = (this.textFrame.parent.toString() == "[object Group]") ? this.textFrame.parent : this.textFrame;

       

        if (obj.toString() == "[object Group]")

        {

        for (i= 0; i < obj.allPageItems.length; i++)

        {

        try {

          obj.allPageItems[i].select();

        } catch (e)

        {

          logger.warn("item in group " + obj.toString() + " can not be selected: " + e);

        }

        }

        } else {

        obj.select();

        }

      }

       

      How to ensure that the selection is extended to ensure that all items within the group are selected?

       

      Thanks

        • 1. Re: How using Extendscript to direct select items in a group?
          Jump_Over Level 5

          Hi,

           

          Use an option of method object.select()

          Assuming some group is selected and your goal is to select ONLY textFrames from this group:

          var
              mGroupItems = app.selection[0].allPageItems,
              cItem;
          app.selection[0] = null;
          while (cItem = mGroupItems.pop())
              if (cItem.constructor.name == "TextFrame")
                  cItem.select(SelectionOptions.ADD_TO);
          

           

          Notice: You can use object.constructor.name to detect which object is targeted currently.

           

          Jarek

          • 2. Re: How using Extendscript to direct select items in a group?
            Laubender Adobe Community Professional & MVP

            Hi Bill,

            if you want to select:

             

            1. All level one pageItems inside a group:

             

            // A group is selected:
            app.select(app.selection[0].pageItems.everyItem().getElements());
            

             

            Example screenshot:

             

            Select-Group.pageItems.everyItem.png

             

            2. If you want to work with allPageItems :

             

            // A group is selected:
            app.select(app.selection[0].allPageItems);
            

             

            Example screenshot:

             

            Select-Group.allPageItems.png

            Note: Also the grouped group itself is selected and also the pasted inside rectangle (yellow) inside that grouped group is selected.

             

            Regards,
            Uwe

            • 3. Re: How using Extendscript to direct select items in a group?
              Laubender Adobe Community Professional & MVP

              But this might not what you want.
              As I can see from your second screenshot the path points of some objects are highlighted.
              You could turn to the Direct Selection Tool first and then do the selection of some of the objects inside of the group.

               

              Example:

               

              // NOTHING IS SELECTED, BUT YOU HAVE IDENTIFIED THE GROUP:
              var group = app.documents[0].groups[0];
              
              // Make the Direct Selection Tool the current one:
              app.toolBoxTools.currentTool = UITools.DIRECT_SELECTION_TOOL;
              
              // Then do the selection:
              app.select([group.pageItems[1], group.pageItems[2]]);
              

               

              Screenshot:

               

              Select-TwoPageItems-of-Group-with-DirectSelectionTool.png

              Regards,
              Uwe

              • 4. Re: How using Extendscript to direct select items in a group?
                Laubender Adobe Community Professional & MVP

                Here the result, if you are using the Selection Tool:

                 

                // In this variant a [object Group] IS selected:
                var item1 = app.selection[0].pageItems[1];
                var item2 = app.selection[0].pageItems[2];
                
                // Define your selection tool:
                app.toolBoxTools.currentTool = UITools.SELECTION_TOOL;
                
                // Alternatively use the Direct Selection Tool:
                // app.toolBoxTools.currentTool = UITools.DIRECT_SELECTION_TOOL;
                
                // Deselect everything first:
                app.select(null);
                // Then select the two items of interest:
                app.select( [ item1 , item2 ] );
                

                 

                It depends what you want to do as next step, if the Selection Tool or the Direct Selection Tool is the right one for you to use if you selectively doing a selection:

                 

                 

                Select-TwoPageItems-of-Group-with-SelectionTool.png

                Regards,
                Uwe