Collect data of model groups

I’m making a script that extracts the information from the shared parameters of the model groups and introduces that data to the same parameters of all the elements that are within the model group. But if the group is repeated at different levels, the information is randomly copied to me does not correspond to its own group. Does anyone know how to sort the information between the group and its all the elements that compose it?

You sort the groups by name and then get the value from the original unsorted group. That’s why they’re “random”. Make sure you’re getting the value from the sorted list.