Yap, I found it. But I don't have all the details.
What EA does it that it stores grouping information in t_diagram.styleEx. E.g. I have grouped two classes and it added
OPTIONS_CA81B41F=GID=0C08:;OPTIONS_D744D373=GID=0C08:;
The OPTIONS_xxx is made from the t_diagramobjects.objectStyle contets. The first of which is
DUID=CA81B41F
So that part is doable, though it needs quite some queries to build the group string.
What I have not found out yet is how the GID=0C08:;
code is built. It might be a random code. Will see if I can get light into that too.
q.