Thursday, September 15, 2011

Clone a vias net to another via

This required a few months of help from Altium, they didn't solve the problem of not being able to add a net to an exsisting via with "not net". But Altium did put me on the right path, the via with "no net" has to be added to the net object, not adding the net to the via (which works if the via already has a net). So this fixes the previous scripts inability to add a net to a via with "no net".

Sub CloneViaNetOBJ
Dim Board
Dim ObjVia
Dim Borg

Set Board = PCBServer.GetCurrentPCBBoard
If Board is Nothing Then Exit Sub
Set ObjVia = Board.GetObjectAtCursor(MkSet(eViaObject)_
,AllLayers,"Select Via to Clone")

NetIterator = Board.BoardIterator_Create
NetIterator.AddFilter_ObjectSet(MkSet(eNetObject))
NetIterator.AddFilter_LayerSet(AllLayers)
NetIterator.AddFilter_Method(eProcessAll)
Set NetFound = NetIterator.FirstPCBObject

While FoundIt = 0 AND Not (NetFound Is Nothing)
      If NetFound.Name = ObjVia.Net.Name Then
         FoundIt = 1
      else
          Set NetFound = NetIterator.NextPCBObject
      End If
Wend

Call PCBServer.PreProcess
While Board.ChooseLocation(x,y, "Click Via To Change") = True
  Set Borg = Board.GetObjectAtXYAskUserIfAmbiguous(x,y,MkSet(_
  eViaObject),AllLayers,eEditAction_Focus)

  If Not(Borg is Nothing) Then
     Call PCBServer.SendMessageToRobots(Borg.I_ObjectAddress,_
     c_Broadcast, PCBM_BeginModify, c_NoEventData)
     'Need to add the via to the net group, not the other way around!
        NetFound.AddPCBObject(borg)
     Call PCBServer.SendMessageToRobots(Borg.I_ObjectAddress,_
     c_Broadcast, PCBM_EndModify , c_NoEventData)
  End If
Wend

Call Board.CleanNet(NetFound) 'How to clean all nets?
Call PCBServer.PostProcess
ResetParameters
Board.BoardIterator_Destroy(NetIterator)
Call AddStringParameter("Action", "Redraw")
RunProcess("PCB:Zoom")
End Sub


Click the via with the net that you want

Then click the ones you want to change.