Learn to use an Iterator that creates a set of objects that meet a certain criteria. This will count the number of pads on the board. Use the AddFilter's to include only the objects that you need.
Sub CountPads
Dim Board
Dim Pad
Dim PadNumber
Dim TotalObjects
Padnumber = 0
Set Board = PCBServer.GetCurrentPCBBoard
If Board is Nothing Then Exit Sub
Iterator = Board.BoardIterator_Create
Iterator.AddFilter_ObjectSet(MkSet(ePadObject))
Iterator.AddFilter_LayerSet(AllLayers)
Iterator.AddFilter_Method(eProcessAll)
Set Pad = Iterator.FirstPCBObject
While Not (Pad Is Nothing)
PadNumber = PadNumber + 1
Set Pad = Iterator.NextPCBObject
Wend
Board.BoardIterator_Destroy(Iterator)
ShowMessage(PadNumber & " Were Found")
End Sub
http://www.tdpcb.com/