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/
Altium Designer Script Information in VB for PCB Layout and Schematic Capture by Bill Smock from Tru Designs, San Diego, CA.
Friday, April 29, 2011
File Name On Visible Layers
Create a sting from the PCB file name and place it on the board but leave off the ending (.pcbdoc). It will place a string on any routing and mechanical layer that is currently enabled and is visible.
Sub AddFileName
Dim Board
Dim ASMSting
Dim Layer
Dim TmpString
Set Board = PCBServer.GetCurrentPCBBoard
If Board is Nothing Then Exit Sub
PCBServer.PreProcess
For Layer = eTopLayer to eMultiLayer
If Board.LayerIsDisplayed(Layer) AND Board.LayerIsUsed(Layer) Then
ASMString = PCBServer.PCBObjectFactory(eTextObject,_
eNoDimension, eCreate_Default)
ASMString.XLocation = Board.XOrigin + MilsToCoord(500) '500 mils from origin in X
ASMString.YLocation = Board.YOrigin - MilsToCoord(500) '-500 mils from origin in Y
TmpString = Board.FileName
'Get rid of the drive and folder portion of the FileName
While Instr(TmpString, "\") <> 0
TmpString = Right(TmpString, Len(TmpString)-Instr(TmpString, "\") ) 'removes the path
Wend
ASMString.Text = Left(TmpString, Instr(TmpString, ".") - 1 ) 'removes the extension
ASMString.Size = MilsToCoord(100) 'Size of the string is 10
ASMString.Layer = Layer
Board.AddPCBObject(ASMString) ' Put this string on the Board
Call PCBServer.SendMessageToRobots(ASMString.I_ObjectAddress, c_Broadcast,_
PCBM_BoardRegisteration, ASMString.I_ObjectAddress)
End If
Next
Pcbserver.PostProcess
ResetParameters
Call AddStringParameter("Action", "Redraw")
RunProcess("PCB:Zoom")
End Sub
http://www.tdpcb.com/
Sub AddFileName
Dim Board
Dim ASMSting
Dim Layer
Dim TmpString
Set Board = PCBServer.GetCurrentPCBBoard
If Board is Nothing Then Exit Sub
PCBServer.PreProcess
For Layer = eTopLayer to eMultiLayer
If Board.LayerIsDisplayed(Layer) AND Board.LayerIsUsed(Layer) Then
ASMString = PCBServer.PCBObjectFactory(eTextObject,_
eNoDimension, eCreate_Default)
ASMString.XLocation = Board.XOrigin + MilsToCoord(500) '500 mils from origin in X
ASMString.YLocation = Board.YOrigin - MilsToCoord(500) '-500 mils from origin in Y
TmpString = Board.FileName
'Get rid of the drive and folder portion of the FileName
While Instr(TmpString, "\") <> 0
TmpString = Right(TmpString, Len(TmpString)-Instr(TmpString, "\") ) 'removes the path
Wend
ASMString.Text = Left(TmpString, Instr(TmpString, ".") - 1 ) 'removes the extension
ASMString.Size = MilsToCoord(100) 'Size of the string is 10
ASMString.Layer = Layer
Board.AddPCBObject(ASMString) ' Put this string on the Board
Call PCBServer.SendMessageToRobots(ASMString.I_ObjectAddress, c_Broadcast,_
PCBM_BoardRegisteration, ASMString.I_ObjectAddress)
End If
Next
Pcbserver.PostProcess
ResetParameters
Call AddStringParameter("Action", "Redraw")
RunProcess("PCB:Zoom")
End Sub
http://www.tdpcb.com/
Labels:
Layer,
PCB File Name,
String
Make A String
Create a sting of various heights and widths on the PCB.
Sub StringCreation
Dim Board
Dim ASMSting
Set Board = PCBServer.GetCurrentPCBBoard
If Board is Nothing Then Exit Sub
PCBServer.PreProcess
For I = 1 to 10
' Create a String object
ASMString = PCBServer.PCBObjectFactory(eTextObject, eNoDimension, eCreate_Default)
ASMString.XLocation = Board.XOrigin + I*MilsToCoord(50)
ASMString.YLocation = Board.YOrigin + I*MilsToCoord(100)
ASMString.Layer = eMechanical7
ASMString.Text = "This Is String #" & I & " with a height of " & (10*I) & " a width of " & I & "mils."
ASMString.Width = MilsToCoord(I)
ASMString.Size = MilsToCoord(10 * I)
Call PCBServer.SendMessageToRobots(ASMString.I_ObjectAddress, c_Broadcast,_
PCBM_BoardRegisteration, ASMString.I_ObjectAddress)
'Put this string on the Board
Board.AddPCBObject(ASMString)
Next
PCBServer.PostProcess
ResetParameters
Call AddStringParameter("Action", "Redraw")
RunProcess("PCB:Zoom")
End Sub
http://www.tdpcb.com/
Sub StringCreation
Dim Board
Dim ASMSting
Set Board = PCBServer.GetCurrentPCBBoard
If Board is Nothing Then Exit Sub
PCBServer.PreProcess
For I = 1 to 10
' Create a String object
ASMString = PCBServer.PCBObjectFactory(eTextObject, eNoDimension, eCreate_Default)
ASMString.XLocation = Board.XOrigin + I*MilsToCoord(50)
ASMString.YLocation = Board.YOrigin + I*MilsToCoord(100)
ASMString.Layer = eMechanical7
ASMString.Text = "This Is String #" & I & " with a height of " & (10*I) & " a width of " & I & "mils."
ASMString.Width = MilsToCoord(I)
ASMString.Size = MilsToCoord(10 * I)
Call PCBServer.SendMessageToRobots(ASMString.I_ObjectAddress, c_Broadcast,_
PCBM_BoardRegisteration, ASMString.I_ObjectAddress)
'Put this string on the Board
Board.AddPCBObject(ASMString)
Next
PCBServer.PostProcess
ResetParameters
Call AddStringParameter("Action", "Redraw")
RunProcess("PCB:Zoom")
End Sub
http://www.tdpcb.com/
Create a Schematic pin in a library part
Places a pin in a schematic library part. Open a schematic library (or create a new one.) Run script and in the current part a pin will be placed.
Sub PlacePin
Set CurrentLib = SchServer.GetCurrentSchDocument
If CurrentLib is Nothing Then Exit Sub
If CurrentLib.ObjectID <> eSchLib Then Exit Sub
Set SchComponent = SchServer.SchObjectFactory(eSchComponent, eCreate_Default)
'Set up parameters for the library component.
SchComponent.CurrentPartID = 1
SchComponent.DisplayMode = 0
'Create pin objects for the new library component.
P1 = SchServer.SchObjectFactory(ePin,eCreate_GlobalCopy)
If P1 is Nothing Then Exit Sub
'Define the pin parameters.
P1.Location = Point(MilsToCoord(250), MilsToCoord( -250 ))
P1.Orientation = eRotate180
P1.PinLength = MilsToCoord(250)
P1.Designator = "1"
P1.Name = "Pin Name"
P1.Electrical = Etype(4) '4=Passive
P1.OwnerPartId = CurrentLib.CurrentSchComponent.CurrentPartID
P1.OwnerPartDisplayMode = CurrentLib.CurrentSchComponent.DisplayMode
SchComponent.AddSchObject(P1)
CurrentLib.RegisterSchObjectInContainer(P1)
'Send a system notification that a new component has been added to the library.
Call AddStringParameter("Action", "Redraw")
RunProcess("SCH:Zoom")
Call SchServer.RobotManager.SendMessage(nil, c_BroadCast, SCHM_PrimitiveRegistration,_ SCHComponent.I_ObjectAddress)
Set CurrentLib.CurrentSchComponent = SchComponent
'Refresh library.
CurrentLib.GraphicallyInvalidate
End Sub
============================
FYI - Electrical definitions for the pin type:
0=Input
1=I/O
2=Output
3=Open Collector
4=Passive
5=HiZ
6=Open Emitter
7=Power
http://www.tdpcb.com/
Sub PlacePin
Set CurrentLib = SchServer.GetCurrentSchDocument
If CurrentLib is Nothing Then Exit Sub
If CurrentLib.ObjectID <> eSchLib Then Exit Sub
Set SchComponent = SchServer.SchObjectFactory(eSchComponent, eCreate_Default)
'Set up parameters for the library component.
SchComponent.CurrentPartID = 1
SchComponent.DisplayMode = 0
'Create pin objects for the new library component.
P1 = SchServer.SchObjectFactory(ePin,eCreate_GlobalCopy)
If P1 is Nothing Then Exit Sub
'Define the pin parameters.
P1.Location = Point(MilsToCoord(250), MilsToCoord( -250 ))
P1.Orientation = eRotate180
P1.PinLength = MilsToCoord(250)
P1.Designator = "1"
P1.Name = "Pin Name"
P1.Electrical = Etype(4) '4=Passive
P1.OwnerPartId = CurrentLib.CurrentSchComponent.CurrentPartID
P1.OwnerPartDisplayMode = CurrentLib.CurrentSchComponent.DisplayMode
SchComponent.AddSchObject(P1)
CurrentLib.RegisterSchObjectInContainer(P1)
'Send a system notification that a new component has been added to the library.
Call AddStringParameter("Action", "Redraw")
RunProcess("SCH:Zoom")
Call SchServer.RobotManager.SendMessage(nil, c_BroadCast, SCHM_PrimitiveRegistration,_ SCHComponent.I_ObjectAddress)
Set CurrentLib.CurrentSchComponent = SchComponent
'Refresh library.
CurrentLib.GraphicallyInvalidate
End Sub
============================
FYI - Electrical definitions for the pin type:
0=Input
1=I/O
2=Output
3=Open Collector
4=Passive
5=HiZ
6=Open Emitter
7=Power
http://www.tdpcb.com/
Wednesday, April 27, 2011
Is this a schematic file?
Checking if the active file is a schematic document.
Sub IsthisaSCHFile
Set CurrentFile = SchServer.GetCurrentSchDocument
If CurrentFile is Nothing Then
ShowMessage ("This is not a SCH file!")
Else
ShowMessage ("This is a SCH file!")
End If
End Sub
http://www.tdpcb.com/
Sub IsthisaSCHFile
Set CurrentFile = SchServer.GetCurrentSchDocument
If CurrentFile is Nothing Then
ShowMessage ("This is not a SCH file!")
Else
ShowMessage ("This is a SCH file!")
End If
End Sub
http://www.tdpcb.com/
Tuesday, April 19, 2011
Counting Pads
Learn to use an Iterator that creates a set of objects that meet a certain criteria. This will count the number of pads on the board. Use the AddFilter's to include only the objects that you need.
Sub CountPads
Dim Board
Dim Pad
Dim PadNumber
Dim TotalObjects
Padnumber = 0
Set Board = PCBServer.GetCurrentPCBBoard
If Board is Nothing Then Exit Sub
Iterator = Board.BoardIterator_Create
Iterator.AddFilter_ObjectSet(MkSet(ePadObject))
Iterator.AddFilter_LayerSet(AllLayers)
Iterator.AddFilter_Method(eProcessAll)
Set Pad = Iterator.FirstPCBObject
While Not (Pad Is Nothing)
PadNumber = PadNumber + 1
Set Pad = Iterator.NextPCBObject
Wend
Board.BoardIterator_Destroy(Iterator)
ShowMessage(PadNumber & " Were Found")
End Sub
http://www.tdpcb.com/
Sub CountPads
Dim Board
Dim Pad
Dim PadNumber
Dim TotalObjects
Padnumber = 0
Set Board = PCBServer.GetCurrentPCBBoard
If Board is Nothing Then Exit Sub
Iterator = Board.BoardIterator_Create
Iterator.AddFilter_ObjectSet(MkSet(ePadObject))
Iterator.AddFilter_LayerSet(AllLayers)
Iterator.AddFilter_Method(eProcessAll)
Set Pad = Iterator.FirstPCBObject
While Not (Pad Is Nothing)
PadNumber = PadNumber + 1
Set Pad = Iterator.NextPCBObject
Wend
Board.BoardIterator_Destroy(Iterator)
ShowMessage(PadNumber & " Were Found")
End Sub
http://www.tdpcb.com/
Sunday, April 17, 2011
Create a Via
Make a few Vias appear on a PCB with the reference being the Board Origin. (FYI learn to decipher TR0138 PCB API Reference.PDF that comes with Altium)
Sub ViaCreation
Dim Board
Dim Via
Set Board = PCBServer.GetCurrentPCBBoard
If Board is Nothing Then Exit Sub
PCBServer.PreProcess
For I = 1 to 10
' Create a Via object
Via = PCBServer.PCBObjectFactory(eViaObject, eNoDimension, eCreate_Default)
Via.X = MilsToCoord (I * 50) + Board.XOrigin
Via.Y = MilsToCoord(I * 50) + Board.YOrigin
Via.Size = MilsToCoord(35)
Via.HoleSize = MilsToCoord(15)
Via.LowLayer = eTopLayer
Via.HighLayer = eBottomLayer
' Put this via in the Board object
Board.AddPCBObject(Via)
Call PCBServer.SendMessageToRobots(Board.I_ObjectAddress, c_Broadcast,_ PCBM_BoardRegisteration, Via.I_ObjectAddress)
Next
PCBServer.PostProcess
ResetParameters
Call AddStringParameter("Action", "Redraw")
RunProcess("PCB:Zoom")
End Sub
These just makes the screen do a refresh
Call AddStringParameter("Action", "Redraw")
RunProcess("PCB:Zoom")
"Undo Stuff"
PreProcess and PostProcess and the Call PCBServer.SendMessageToRobots(Board.I_ObjectAddress, c_Broadcast, PCBM_BoardRegisteration, Via.I_ObjectAddress)
allow the "Undo" to work with what was just placed on the board, otherwise is may not know that they were added.
http://www.tdpcb.com/
Sub ViaCreation
Dim Board
Dim Via
Set Board = PCBServer.GetCurrentPCBBoard
If Board is Nothing Then Exit Sub
PCBServer.PreProcess
For I = 1 to 10
' Create a Via object
Via = PCBServer.PCBObjectFactory(eViaObject, eNoDimension, eCreate_Default)
Via.X = MilsToCoord (I * 50) + Board.XOrigin
Via.Y = MilsToCoord(I * 50) + Board.YOrigin
Via.Size = MilsToCoord(35)
Via.HoleSize = MilsToCoord(15)
Via.LowLayer = eTopLayer
Via.HighLayer = eBottomLayer
' Put this via in the Board object
Board.AddPCBObject(Via)
Call PCBServer.SendMessageToRobots(Board.I_ObjectAddress, c_Broadcast,_ PCBM_BoardRegisteration, Via.I_ObjectAddress)
Next
PCBServer.PostProcess
ResetParameters
Call AddStringParameter("Action", "Redraw")
RunProcess("PCB:Zoom")
End Sub
These just makes the screen do a refresh
Call AddStringParameter("Action", "Redraw")
RunProcess("PCB:Zoom")
"Undo Stuff"
PreProcess and PostProcess and the Call PCBServer.SendMessageToRobots(Board.I_ObjectAddress, c_Broadcast, PCBM_BoardRegisteration, Via.I_ObjectAddress)
allow the "Undo" to work with what was just placed on the board, otherwise is may not know that they were added.
http://www.tdpcb.com/
Labels:
Vias
Thursday, April 14, 2011
Is this A PCB file?
Most of the scripts will be for the PCB editor, so I need to check and make sure when I run a script it's actully being run in a PCB file. Access the PCBServer to get things started.
Sub IsthisaPCBFile
Set Board = PCBServer.GetCurrentPCBBoard
If Board is Nothing Then
ShowMessage ("This is not a PCB file!")
Else
ShowMessage ("This is a PCB file!")
End I
End Sub
If a pcb file isn't active in Altium then
Else if a PCB file is active
http://www.tdpcb.com/
Sub IsthisaPCBFile
Set Board = PCBServer.GetCurrentPCBBoard
If Board is Nothing Then
ShowMessage ("This is not a PCB file!")
Else
ShowMessage ("This is a PCB file!")
End I
End Sub
If a pcb file isn't active in Altium then
Else if a PCB file is active
http://www.tdpcb.com/
Alitum Designer Script Notes Visual Basic (VB)
Just some running notes as I learn to write VB scripts for Altium.
Starting with the very basics.
In Altium Designer choose File, New, Script Files, VB Script Unit Paste this:
Starting with the very basics.
In Altium Designer choose File, New, Script Files, VB Script Unit Paste this:
Sub ShowMessageBox
ShowMessage ("Hello! It's " & Time )
End Sub
Run the Script (DXP, Run Script, Choose ShowMessageBox) and you get
Subscribe to:
Posts (Atom)