Skip to main content
Inspiring
July 30, 2013
Answered

Ungroup all groups then create a single group

  • July 30, 2013
  • 1 reply
  • 2514 views

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.move(whereToUngroup, ElementPlacement.PLACEATBEGINNING);

     }

But I'm having trouble getting it to work.

This topic has been closed for replies.
Correct answer CarlosCanto

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.

1 reply

CarlosCanto
Community Expert
Community Expert
July 30, 2013

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?

Inspiring
July 30, 2013

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.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

CarlosCanto
Community Expert
CarlosCantoCommunity ExpertCorrect answer
Community Expert
July 30, 2013

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.