Layout nodes in a group upon group creation

My program enables the user to group nodes on demand, by site key.
When the user presses some button, the application group the nodes by site key.
The groups are layout using groupLayout.
I would like the nodes within a group to be layout, for example circular layout.
I noticed that if the created group is not expanded, the layout algorithm does not work.
Is that so ?
The workaround it, the group template is set the isSungraphExpanded=true
and right after the group is created, i wait, one second (setTimeout) and collapse the group.
Any other way to layout nodes within a group, upon group creation ?

I’m not clear on why you need the nodes laid out if the group isn’t yet expanded. Why isn’t laying them out the first time the group expands sufficient?

You’re a mind reader…
This is what i exactly thought right now.
So, if i want to layout the group when it is first exaplnded, what should i do ?
Like this :
if (firstTime) {
group.layout = $(go.SomeLayout…)
And then, i want to stop the auto layout so, i should do ?
group.IsInitial = false;
When ?
After one second (serTimeout…)

any suggestion ?

What about subsequent times that you collapse and expand? Should the nodes be laid out every time the group gets expanded, or just the first?

You can probably set the Layout.isOngoing to false, then use a Group.subGraphExpandedChanged function to perform the layout when you want to.