Friday, April 29, 2011

Moving Designators

Rotate the designators in one of two ways and center them on the component so they are consistant.
Also detect if the component is on the top or the bottom.

Sub RotateDesignators
Dim Board
Dim Component
Dim CompDes
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 CompDes = Iterator.FirstPCBObject
PCBServer.PreProcess
I = 0
While Not (CompDes Is Nothing)
  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
    Case Else
       CompDes.Name.Rotation  = 0
    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
    Case Else
       CompDes.Name.Rotation  = 0
    End Select
  End If

  CompDes.ChangeNameAutoposition = eAutoPos_CenterCenter
  Call PCBServer.SendMessageToRobots(CompDes.Name.I_ObjectAddress,_
c_Broadcast, PCBM_EndModify , c_NoEventData)

  Set CompDes = Iterator.NextPCBObject
Wend
'Uncomment next line if you want a message after it has finished.
'ShowMessage(I & " were found")
Board.BoardIterator_Destroy(Iterator)
Pcbserver.PostProcess
ResetParameters
Call AddStringParameter("Action", "Redraw")
RunProcess("PCB:Zoom")
End Sub



http://www.tdpcb.com/