Tuesday, May 03, 2011

Selected Components

Count how many components are currently selected in the PCB.

Sub HowManyCompsSelected

Dim Board
Dim Component
Dim I

Set Board = PCBServer.GetCurrentPCBBoard
If Board is Nothing Then Exit Sub

Iterator = Board.BoardIterator_Create
Iterator.AddFilter_ObjectSet(MkSet(eComponentObject))
Iterator.AddFilter_LayerSet(AllLayers)
Iterator.AddFilter_Method(eProcessAll)

Set Component= Iterator.FirstPCBObject
PCBServer.PreProcess
I = 0

While Not(Component is Nothing)

  If Component.Selected = True Then
     I = I + 1
  End If
  Set Component= Iterator.NextPCBObject

Wend
ShowMessage(I & " selected.")
Board.BoardIterator_Destroy(Iterator)
Pcbserver.PostProcess
ResetParameters
Call AddStringParameter("Action", "Redraw")
RunProcess("PCB:Zoom")

End Sub

 
 
http://www.tdpcb.com/