I don’t know if the code here (originally for switches) will be any help to you - but it does loop over the attributes.