3 Replies Latest reply on Jul 31, 2013 10:52 AM by CarlosCanto

    Making all paths into a group without selection

    Prails.deisgn Level 1

      I'm working on a script that will take every pathItem in a document and put it into a group (all pathItems in the document are groupless upon opening it, so there won't be other groups already in the document).

       

      I have a script that creates a group, then puts the highest placed pathItem into the group. I just can't figure out how to have to grab all pathitems in the document, or loop this one action until everything is in a single group. Also the kicker is, as the title suggests this script has to work without selecting anything by hand first (in other words having to click something to select it). Now if there's was a way to select everything with a script that would be awesome.

       

      Here's what I have so far:

       

       

      #target Illustrator
      //based on script from Carlos Canto
      var doc = app.activeDocument
      
      if ( app.documents.length > 0 ) {
      doc = app.activeDocument;
      newGroupItem = doc.activeLayer.groupItems.add();
      }
      
      var gi = doc.groupItems[0]; // the topmost existing group
      var all = doc.pathItems[0]; // all paths in document
      
      all.move (gi, ElementPlacement.PLACEATBEGINNING); // move selected path inside the group
      all.evenodd = true; // necessary to determine "insideness" or to make holes.
      
      

       

      I also have this that I found here on the forum

       

      #target Illustrator
      // GroupFromSel.jsx
      // regards pixxxelschubser 
      if ( app.documents.length > 0 && app.activeDocument.selection.length > 0) {
          var aDoc = app.activeDocument;
          var Sel = aDoc.selection;
          var GroupFromSel = aDoc.groupItems.add();
          for ( i = Sel.length-1; i >= 0; i--) {
              Sel[i].moveToBeginning( GroupFromSel )
              }
      }
      
      

       

      But saddly it requires selecting so two scripts, two possible solutions. I'm just working on both until I can get one to work.

       

      Any ideas?

        • 1. Re: Making all paths into a group without selection
          CarlosCanto Adobe Community Professional & MVP

          var all = doc.pathItems[0]; // all paths in document

          that's only the top most pathItem, change that to

          var all = doc.pathItems; // all paths in document

           

          ...and loop thru "all" and move each inside your group

          #target Illustrator
          //based on script from Carlos Canto
          
          if ( app.documents.length > 0 ) {
              doc = app.activeDocument;
              var gi = doc.activeLayer.groupItems.add();
              var all = doc.pathItems; // all paths in document
              
              for (i=0; i<all.length; i++) {
                  eachPath = all[i];
                  eachPath.move (gi, ElementPlacement.PLACEATBEGINNING); // move all pathItems inside the group
              }
          }
          else
              alert('no documents to process');
          

           

          for this set up we will run into trouble if you have other groups with pathItems

          • 2. Re: Making all paths into a group without selection
            Prails.deisgn Level 1

            Ah! I totally get it ok, yes! [0] was just the first pathItem

             

            for (i=0; i<all.length; i++)

             

            That's what I was missing to have it go through and grab each pathItem after the last through the entire document.

            Javascript is finally starting to click with me.

             

            Carlos you're a live saver man.

            When I hit it big some day I'll remember you.

            • 3. Re: Making all paths into a group without selection
              CarlosCanto Adobe Community Professional & MVP

              When I hit it big some day I'll remember you.

               

              hahaha...we'll see