Monday, May 09, 2011

Rotate and Center Designators of Selected Parts.

Build upon a previous script, rotate and center designators for only selected parts.

Sub RotateSelectedDesignators

Dim Board
Dim Component
Dim CompDes
Dim I
Set Board = PCBServer.GetCurrentPCBBoard
If Board is Nothing Then Exit Sub
BeginHourGlass
Iterator = Board.BoardIterator_Create
Iterator.AddFilter_ObjectSet(MkSet(eComponentObject))
Iterator.AddFilter_LayerSet(AllLayers)
Iterator.AddFilter_Method(eProcessAll)
Set CompDes = Iterator.FirstPCBObject
PCBServer.PreProcess
I = 0

While Not (CompDes Is Nothing)

  If CompDes.Selected = True Then
    Call PCBServer.SendMessageToRobots(CompDes.Name.I_ObjectAddress,_
    c_Broadcast, PCBM_BeginModify, c_NoEventData)
    I = I + 1
    If CompDes.Layer = eTopLayer then           'Component is on the top
       Select Case CompDes.Rotation
           Case 0, 180, 360
                CompDes.Name.Rotation  = 0
           Case 90, 270
                CompDes.Name.Rotation  = 90
       End Select
       else                                     'Component is on the bottom
       Select Case CompDes.Rotation
           Case 0, 180, 360
                CompDes.Name.Rotation  = 0
           Case 90, 270
                CompDes.Name.Rotation  = 270
       End Select
    End If
       Call PCBServer.SendMessageToRobots(CompDes.Name.I_ObjectAddress,_
       c_Broadcast, PCBM_EndModify , c_NoEventData)
       Call PCBServer.SendMessageToRobots(CompDes.Name.I_ObjectAddress,_
       c_Broadcast, PCBM_BeginModify, c_NoEventData)
       CompDes.ChangeNameAutoposition = eAutoPos_CenterCenter
       Call PCBServer.SendMessageToRobots(CompDes.Name.I_ObjectAddress,_
       c_Broadcast, PCBM_EndModify , c_NoEventData)
  End if
       Set CompDes = Iterator.NextPCBObject
Wend

'Uncomment this line if you want a message after it has finished.
'ShowMessage(I & " were found")
If I = 0 then
   ShowMessage("No parts were selected.")
End If
Board.BoardIterator_Destroy(Iterator)
Pcbserver.PostProcess
EndHourGlass
Call AddStringParameter("Action", "Redraw")
RunProcess("PCB:Zoom")
End Sub