I'm not entirely clear what you want to do but have a look at: File > Automate > Contact Sheet II...
Ah, sorry for the confusion. Let me be more specific.
I'm creating artwork in photoshop that is being exported out to animation software via their own script. Their script will save out visible layers but ignores groups. While working I'd like the ability to quickly flatten all groups individually so that I can export them out to the animation software, at which point I'll just undo that action and be able to fix mistakes, add details, etc.
In short: the manual action I'm taking is highlighting each individual group, right clicking, and selecting "merge group". I'd like an automated way to do this to all my groups at once (there are about 30 per illustration so doing them manually is a chore).
I still don't understand, to be honest, but have a look at: File > Scripts > Image Processor to see if it offers anything you can use.