I don’t love this method, but it’s certainly doable.
However, instead of tracking materials I would track either their names or their marks in a single string, with new lines in between each value (the old
alt + enter trick in excel). It’s pretty easy to write a graph that pulls the materials from the layer via Dynamo. This will be easier to edit, manage, and control over the life of the project. A lot faster to set the values as well.
Look into the clockwork package for the Compound Layer Structure node. From there it’s just pulling the values (either name or mark) from the materials with an Element.GetParameterValueByName node, and setting those values (and any other data you’d like to add) to a single ‘material assembly’ parameter with an "Element.SetParameterByName node.
Give it a shot and see where you get, as this is a pretty good ‘starter’ graph.