Creating list based on layers and property value

Hi there,

I’m working on a BIM models in Civil3D and currently I’m trying to write a script that will help me to simplify making the needed report. The aim of this script is to export an excel table where on top of the column, there are all the name of the roads of the current model and underneath the road name there will be the quantities of the road. But on the rows the quantities are sorted by the layers (every layer is a different material in my case). The outcome should be something like this:


I have done the part of the script where it sorts everything based on the layer and it works fine. But the part where I add that the quantities on every layer considering the road name as well and are put on the right column - it gets messy for me and that’s where I’m stuck. All of the roads do not consider every material and in some cases there might be two quantites of the same material at the same road - so I need to summarise them etc.

This is what I have come up with.

Hopefully the explanation is clear enough!

Thanks in advance…
Eno