5 Replies Latest reply on Jul 31, 2013 8:15 AM by CarlosCanto

    Ungroup all groups then create a single group

    Prails.deisgn Level 1

      Hey

       

      I'm having trouble getting a script together where I can ungroup all groups in a document, then put everything under a single group. Everyhting I'm working with has a single layer, but for some of the arts I'm importing have groups within groups ect. To run certain actions I've made properly after I need eveything to be in one, single group.

       

      I searched for an answer and found this (wirtten by Carlos Canto)

       

      function ungroup(whereToUngroup, group) // where to ungroup? layer, document, other group?

           {

                for (i=group.pageItems.length-1; i>=0; i--)

                     group.pageItems[i].move(whereToUngroup, ElementPlacement.PLACEATBEGINNING);

           }

       

      But I'm having trouble getting it to work.

        • 1. Re: Ungroup all groups then create a single group
          CarlosCanto Adobe Community Professional & MVP

          But I'm having trouble getting it to work.

          why? are you having problems understanding the parameters of the function? what are you having trouble with?

          • 2. Re: Ungroup all groups then create a single group
            Prails.deisgn Level 1

            Ya, I guess im just not putting in the correct information. I'm certain your code works, I just am too inexperienced to know how to use it.

             

            Here's what I tried to put in.

             

             

            function ungroup(Layer, group) // where to ungroup? layer, document, other group?

                 {

                      for (i=group.pageItems.length-1; i>=0; i--)

                           group.pageItems[i].move(Layer, ElementPlacement.PLACEATBEGINNING);

                 }

             

             

            I'm only one week into javascript and coding for illustrator so I just don't know either well enough yet. But I'm leanring a lot each day messing around with both so eventually I'll get there

            • 3. Re: Ungroup all groups then create a single group
              CarlosCanto Adobe Community Professional & MVP

              ok, that's fair...

               

              Functions 101 - you don't suppose to change anything, you suppose to build one (or someone else) and use it and re-use it. You just provide the parameters the function was build to receive.

               

              to call the function (to use the function) provide it with your own parameter names, they don't have to match the original function names.

               

              var myGroup = blablabla....the group you want to ungroup

              var myDestinationGroup = blablabla....the group where you want the items once ungrouped, this could be a Layer or a Document

               

              ungroup(myDestinationGroup, myGroup); // call the function

               

               

              since you're new to scripting and new here, I would suggest start off good and mark your questions as "correct" (or answered, I don't remember) whenever you get a satisfactory answer to somewhat close the thread, you don't have to if you think you didn't get the answer you were looking for.

              • 4. Re: Ungroup all groups then create a single group
                Prails.deisgn Level 1

                Thank you very much, I'm basically at the stage where I take code read it over and over, change values ect to see what it does to understand it, but this was insiteful! Thanks a bunch dude!

                • 5. Re: Ungroup all groups then create a single group
                  CarlosCanto Adobe Community Professional & MVP

                  you're welcome, you're doing good so far, it takes some time and a lot of reading to grasp the concepts, fortunately there are lots and lots of snippets about every topic posted in this forum (search is your friend), and if you get stuck or need help you can always come here for help