If you are talking about Xpedition, Vias are a collection and these are the collection methods exposed:
I guess you could get the zoom extents, and walk through the vias collection and throw out the ones that are not inside the display coordinates. I usually have the user select or mark or highlight the ones they are interested in.
The following code is for vb.net. If you use vbs or another language, it will be slightly different: It assumes that doc is the PCB document object, and has been declared and initialized elsewhere.
Dim view As MGCPCB.View
Dim ext As MGCPCB.Extrema
Dim pstk As MGCPCB.PadstackObject
Dim n As Integer
Dim vias As MGCPCB.Vias
Dim via As MGCPCB.Via
view = doc.ActiveViewEx
ext = view.Extrema
pstks = doc.Pick(ext.MinX,ext.MinY,ext.MaxX, ext.MaxY, 1, , True, False)
n = 0
For Each pstk In pstks
If pstk.Type = 2 Then
n = n + 1
pstk.Selected = True
Debug.Print("found " & n & " vias")
vias = doc.Vias(1)
For Each via In vias
Debug.Print("via on net " & via.Net.Name & " found at " & via.PositionX & "," & via.PositionY)
The pick method of the document object is the key. The layerobjects argument of the pick method is not needed in this case, so it is omitted. The last two arguments (visible and get items on components) are also optional and could also probably be left out.
The trick to using the pick method is to only select a generic object type as the receiving variable (pstks in this case). If you try to use a data type with this variable, it won't work. When you later iterate through the selected items, you use a typed variable (pstk) to do that, and then you get all the appropriate properties and methods of that data type.
If you have a design with many vias, this method will be much faster than iterating through all the vias in the design.