To count all the vias in a brd file,
- Set the find filter to only Vias
- Turn on only the Via Class layers
- Select All
- Get the length of the selection set
To sort them by padstack you will need to loop on the selection set (foreach would be best) and put them into lists (or table) by padstack name. Then you can print the xy location for each padstack name.
Post your code, to get some feedback.