This will swap the positions of two components that are choosen, including the rotation of the part and the rotation and position of the designators. Based on a script that came with Summer '09 but more useful. If a component is not selected the script will end to avoid a crash.
Sub SwapComps
Dim Board
Dim CompA
Dim CompB
Dim CompX
Dim CompY
Dim CompR
Dim DesX
Dim DesY
Dim DesR
Set Board = PCBServer.GetCurrentPCBBoard
If Board is Nothing Then Exit Sub
Pcbserver.PreProcess
While Board.ChooseLocation(x,y, "Select First Componet") = True
Set CompA = Board.GetObjectAtXYAskUserIfAmbiguous(x,y,MkSet(eComponentObject)_
,AllLayers, eEditAction_Select)
If CompA Is Nothing Then Exit Sub 'Needed, if no comp is selected, crash
Call Board.ChooseLocation(x,y, "Select Second Componet")
Set CompB = Board.GetObjectAtXYAskUserIfAmbiguous(x,y,MkSet(eComponentObject)_
,AllLayers, eEditAction_Select)
If CompB Is Nothing Then Exit Sub 'Needed, if no comp is selected, crash
CompX = CompA.X
CompY = CompA.Y
CompR = CompA.Rotation
DesX = CompA.Name.XLocation
DesY = CompA.Name.YLocation
DesR = CompA.Name.Rotation
Call PCBServer.SendMessageToRobots(CompA.I_ObjectAddress,c_Broadcast,_
PCBM_BeginModify, c_NoEventData)
CompA.X = CompB.X
CompA.Y = CompB.Y
CompA.Rotation = CompB.Rotation
CompA.ChangeNameAutoposition = eAutoPos_Manual
Call PCBServer.SendMessageToRobots(CompA.I_ObjectAddress,c_Broadcast,_
PCBM_EndModify , c_NoEventData)
Call PCBServer.SendMessageToRobots(CompA.Name.I_ObjectAddress, c_Broadcast,_
PCBM_BeginModify, c_NoEventData)
CompA.Name.XLocation = CompB.Name.XLocation
CompA.Name.YLocation = CompB.Name.YLocation
CompA.Name.Rotation = CompB.Name.Rotation
Call PCBServer.SendMessageToRobots(CompA.Name.I_ObjectAddress, c_Broadcast,_
PCBM_EndModify , c_NoEventData)
Call PCBServer.SendMessageToRobots(CompB.I_ObjectAddress,c_Broadcast,_
PCBM_BeginModify, c_NoEventData)
CompB.X = CompX
CompB.Y = CompY
CompB.Rotation = CompR
CompB.ChangeNameAutoposition = eAutoPos_Manual
Call PCBServer.SendMessageToRobots(CompB.I_ObjectAddress,c_Broadcast,_
PCBM_EndModify , c_NoEventData)
Call PCBServer.SendMessageToRobots(CompB.Name.I_ObjectAddress, c_Broadcast,_
PCBM_BeginModify, c_NoEventData)
CompB.Name.XLocation = DesX
CompB.Name.YLocation = DesY
CompB.Name.Rotation = DesR
Call PCBServer.SendMessageToRobots(CompB.Name.I_ObjectAddress, c_Broadcast,_
PCBM_EndModify , c_NoEventData)
Wend
Pcbserver.PostProcess
ResetParameters
Call AddStringParameter("Action", "Redraw")
RunProcess("PCB:Zoom")
End Sub
www.tdpcb.com
Altium Designer Script Information in VB for PCB Layout and Schematic Capture by Bill Smock from Tru Designs, San Diego, CA.
Showing posts with label Components. Show all posts
Showing posts with label Components. Show all posts
Wednesday, June 08, 2011
Monday, June 06, 2011
Set the DRC error for a component
Simple test to look for the "R2" componet and set it's DRC flag.
Sub SetDRC
Dim Board
Dim CompDes
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(eProcessComponents)
Set CompDes = Iterator.FirstPCBObject
PCBServer.PreProcess
While Not(CompDes Is Nothing)
If CompDes.Name.Text = "R2" then
CompDes.SetState_DRCError = True
End If
Set CompDes = Iterator.NextPCBObject
Wend
Board.BoardIterator_Destroy(Iterator)
Pcbserver.PostProcess
ResetParameters
Call AddStringParameter("Action", "Redraw")
RunProcess("PCB:Zoom")
End Sub
www.tdpcb.com
Sub SetDRC
Dim Board
Dim CompDes
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(eProcessComponents)
Set CompDes = Iterator.FirstPCBObject
PCBServer.PreProcess
While Not(CompDes Is Nothing)
If CompDes.Name.Text = "R2" then
CompDes.SetState_DRCError = True
End If
Set CompDes = Iterator.NextPCBObject
Wend
Board.BoardIterator_Destroy(Iterator)
Pcbserver.PostProcess
ResetParameters
Call AddStringParameter("Action", "Redraw")
RunProcess("PCB:Zoom")
End Sub
Labels:
Components,
Designators,
DRC
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
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
Labels:
Components,
Designators,
Select
Thursday, May 05, 2011
GetObject at cursor to pick a component.
Using the GetObject to choose what component to reset the designator to center/center.
Press escape to end action.
Sub ChooseDesReset
Dim Board
Dim Comp
Dim x,y
Set Board = PCBServer.GetCurrentPCBBoard
Call PCBServer.PreProcess
While Board.ChooseLocation(x,y, "Choose Component") = True
Set Comp = Board.GetObjectAtXYAskUserIfAmbiguous(x,y,MkSet(_
eComponentObject),AllLayers,eEditAction_Focus)
If Not(Comp is Nothing) Then
Call PCBServer.SendMessageToRobots(Comp.Name.I_ObjectAddress,_
c_Broadcast, PCBM_BeginModify, c_NoEventData)
Comp.ChangeNameAutoposition = eAutoPos_CenterCenter
Call PCBServer.SendMessageToRobots(Comp.Name.I_ObjectAddress,_
c_Broadcast, PCBM_EndModify , c_NoEventData)
End If
Wend
Call PCBServer.PostProcess
ResetParameters
Call AddStringParameter("Action", "Redraw")
RunProcess("PCB:Zoom")
End Sub
http://www.tdpcb.com/
Press escape to end action.
Sub ChooseDesReset
Dim Board
Dim Comp
Dim x,y
Set Board = PCBServer.GetCurrentPCBBoard
Call PCBServer.PreProcess
While Board.ChooseLocation(x,y, "Choose Component") = True
Set Comp = Board.GetObjectAtXYAskUserIfAmbiguous(x,y,MkSet(_
eComponentObject),AllLayers,eEditAction_Focus)
If Not(Comp is Nothing) Then
Call PCBServer.SendMessageToRobots(Comp.Name.I_ObjectAddress,_
c_Broadcast, PCBM_BeginModify, c_NoEventData)
Comp.ChangeNameAutoposition = eAutoPos_CenterCenter
Call PCBServer.SendMessageToRobots(Comp.Name.I_ObjectAddress,_
c_Broadcast, PCBM_EndModify , c_NoEventData)
End If
Wend
Call PCBServer.PostProcess
ResetParameters
Call AddStringParameter("Action", "Redraw")
RunProcess("PCB:Zoom")
End Sub
Labels:
Components,
Cursor,
GetObject
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/
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/
Labels:
Components,
Select
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/
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/
Labels:
Components,
Designators
Subscribe to:
Posts (Atom)





