Copy link to clipboard
Copied
Does anyone know how one would go about ungrouping all groups on an active layer with JavaScript?
you're looking for "Recursion", check this thread, Mark has a sample of how to recurse layers and groups.
Copy link to clipboard
Copied
there are no group or ungroup commands, to group you create a groupItem Object and move stuff inside it. To ungroup, you take stuff out of the group (move them out).
Copy link to clipboard
Copied
bummer.
Thanks for the info.
Could anyone give an example of moving pageItems out of a group of the active layer?
I know how to get the value of all the group Items in an active layer but I do not know the proper syntax to use to pull the page items out of it.
Copy link to clipboard
Copied
look here, I made an "ungroup" function
Copy link to clipboard
Copied
Awesome! I have more than one group on the layer and by adding a For loop to get the value of all groups I was able to use your example to get those groups out of there.
var myLayer = app.activeDocument.activeLayer;
var group = thisDoc.activeLayer.groupItems;
for (d=0;d<group.length;d++){
var mygroups = group
for (i=mygroups.pageItems.length-1; i>=0; i--)
mygroups.pageItems.move(myLayer, ElementPlacement.PLACEATBEGINNING);
}
Unfortunately I will have groups within groups from time to time. Do you know a way to make the script check for groups on the active layer over and over till there are no more groups? It escapes me.
Thanks for your help,
Duane
Copy link to clipboard
Copied
you're looking for "Recursion", check this thread, Mark has a sample of how to recurse layers and groups.