Pilou - nascent scripter - yours I think... π
Iterate through model.definitions, if defn.group? then add if to a groups array and then iterate through groups and rename each group to match its group.layer.name, keep a list of all group names as you go [start by making a list of the groups' names and then remove old name and add new name as you go groups]. It a group name exists then increment it [tip: name="name#1";name=name.next if groupnames.include?(name)] - several groups could be on one layer and should them get named name#1,name#2,name#3 etc...