Friday, May 20, 2011

Place a track and via with the choosen pad net assigned to them.

Select a pad with a net and a stinger (a track and a via) will be placed with the pads net.

Sub TagPadWithNet

Dim Board
Dim Track
Dim Via
Dim NetObject
Dim PadX
Dim PadY
Dim PadNet
Dim ViasSize
Dim ViaHole

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

NetObject = Board.GetObjectAtCursor(MkSet(ePadObject),AllLayers,"Select Net")
PadX = CoordToMils(NetObject.X)
PadY = CoordToMils(NetObject.Y)
PadNet = NetObject.Net.Name
X1 = PadX
X2 = PadX - CoordToMils(NetObject.TopXSize) - 10
Y1 = PadY
Y2 = PadY
Layer = NetObject.Layer
Width = 10
Call PCBServer.PreProcess

'Add the Track
Track           = PCBServer.PCBObjectFactory(eTrackObject, eNoDimension, eCreate_Default)
Track.X1        = MilsToCoord(X1)
Track.X2        = MilsToCoord(X2)
Track.Y1        = MilsToCoord(Y1)
Track.Y2        = MilsToCoord(Y2)
Track.Layer     = Layer
Track.Net       = NetObject.Net
Track.Width     = MilsToCoord(Width)
Call PCBServer.SendMessageToRobots(Board.I_ObjectAddress,_
 c_Broadcast, PCBM_BoardRegisteration, Track.I_ObjectAddress)

'Add the via
ViaSize = 26
ViaHole = 12
Via           = PCBServer.PCBObjectFactory(eViaObject, eNoDimension, eCreate_Default)
Via.X         = MilsToCoord(X2)
Via.Y         = MilsToCoord(Y2)
Via.Size      = MilsToCoord(ViaSize)
Via.HoleSize  = MilsToCoord(ViaHole)
Via.LowLayer  = eTopLayer
Via.HighLayer = eBottomLayer
Via.Net       = NetObject.Net
Call PCBServer.SendMessageToRobots(Board.I_ObjectAddress,_
 c_Broadcast, PCBM_BoardRegisteration, Via.I_ObjectAddress)

Call PCBServer.PostProcess
Call AddStringParameter("Action", "Redraw")

End Sub