Copying calculated field values to a parameter-based field

The goal:
To copy all values from a calculated value column determining the occupant load of rooms to a corresponding parameter-based column for use in room tagging.

I have the following script.

The first problem I’m having is the Set Param at the end is failing saying the parameter’s storage type is not a string. I think, but am not sure, that this is due to some of the fields in the column having a null value. I added the ToNumber (the param is set to be an integer) to cast the potentially string value to a number, but that also generates an error. Again, I think this might also be because of the null values in some fields. This does appear to fill in the fields as desired, though. Do I need some way of ignoring the null fields or just let the error happen?

Second problem that doesn’t seem to be breaking the final outcome, is the collection of the calculated field column is also grabbing the final overall total. In this example, I have a total of 38 rooms, but I’m getting 39 values in the calculated field list.

Third problem that isn’t really a problem, yet. I am collecting the rooms and then sorting by room number. The schedule is sorted by level and then by room number and that is the order, I assume, that the calculated value list is always going to be in. It would follow the order of the schedule, right? How would I order the rooms list by level, then by number to make sure the ordering is the same in both lists?

Finally, if anyone can offer any better ways to handle any portion of this, I’m all ears. I’m still very much a novice at Dynamo!!!

Thanks!
Matt


Update. I found an example of sorting based on multiple params, so I updated the script. I assume this works.

Biggest problem is the field totals being included in the calculated fields list. Need to strip those out some how or find a better way to map each room’s fields to each other. See the second image. You can see how the 171 total is used in the following field and then throws everything off.

Also converted all nulls to zero before sending the values to SetParam, but I still get this error (although it seems to work fine):
Warning: Element.SetParameterByName operation failed.
The call is ambiguous between the following methods or properties:
‘Revit.Elements.InternalUtilities.ElementUtils.SetParameterValue(Autodesk.Revit.DB.Parameter, Revit.Elements.Element)’ and
‘Revit.Elements.InternalUtilities.ElementUtils.SetParameterValue(Autodesk.Revit.DB.Parameter, string)’


I THINK I have it working.

I used another field that doesn’t have tallies to filter the one that does.