導出BOM是硬件工程師在設計PCB時必備的一項任務。通常情況下,導出的BOM中并沒有區分頂層和底層的元器件,但是有時候我們需要對這兩者進行分開,以便更好地進行統計和管理。
本文將介紹如何通過編寫PADS的BOM的導出腳本代碼實現這個功能。
首先,我們需要了解腳本中的原理。在PADS導出BOM的腳本中,一般會讀取元器件的相關信息,如元器件編號、名稱、數量等。我們需要在腳本中增加元器件層信息的讀取,以及在整理元器件時對層信息進行判斷,從而實現元器件分頂層和底層的歸類統計。
編寫以下代碼:
代參考代碼:
Const Columns = Array("Item","Description","Value","PCB Decal","Ref","OPTION","Quantity","layer")
'Array of column alignment: 0 - Align Left, 1 - Align Right, 2 - Align Center.
Const Align= Array(0,0,0,0,0,0,0)
Dim fname As String
Sub Main
fname = ActiveDocument
If fname = "" Then
fname = "Untitled"
End If
tempFile = DefaultFilePath & " emp.txt"
Open tempFile For Output As #1
StatusBarText = "Generating report..."
'Output table header
For i = 0 To UBound(Columns)
OutCell Columns(i)
Next
Print #1
Dim part_Count As Integer
part_Count = 0
For Each part In ActiveDocument.Components
If part.Pins.Count > 1 Then
part_Count = part_Count + 1
End If
Next part
ReDim Parts(part_Count, 14) As String
For Each part In ActiveDocument.Components
If part.Pins.Count > 1 Then
For intJ = 1 To 8
Parts(intI,1) = ""
Parts(intI,2) = AttrVal(part, "Description")
Parts(intI,3) = AttrVal(part, "Value")
Parts(intI,4) = part.Decal
Parts(intI,5) = part.Name
Parts(intI,6) = AttrVal(part, "Option")
Parts(intI,7) = ""
Parts(intI,8) =ActiveDocument.LayerName(part.layer)
Next intJ
intI= intI + 1
End If
Next part
Dim comp_counter As Integer
Dim Species As Integer
Const flag As Integer = 10
Dim Component As String
Dim Component_tempAs String
Dim label As String
comp_counter = 0
Species = 0
For i = 1 To UBound(Parts, 1)
If Parts(i, flag) = "" Then
Component = Parts(i, 2) &Parts(i, 6)
label = Parts(i, 5)
comp_counter = 1
For j = i + 1 To UBound(Parts, 1)
Component_temp =Parts(j, 2) &Parts(j, 6)
If Component = Component_temp Then
comp_counter = comp_counter + 1
label = label & ", " &Parts(j, 5)
Parts(j, flag) = "0"
End If
Next j
Parts(i, 5) = label
Parts(i, 7) = Str(comp_counter)
Species = Species + 1
End If
Next i
Dim NO_ As Integer
ReDim SpeciesArray1(Species, 8)
ReDim SpeciesArray2(Species, 8)
NO_ = 1
For i = 1 To UBound(Parts, 1)
If Parts(i, flag) = "" And Parts(i, 8)="TOP" Then
SpeciesArray1(NO_, 1) = Parts(i, 1)
SpeciesArray1(NO_, 2) = Parts(i,2)
SpeciesArray1(NO_, 3) = Parts(i,3)
SpeciesArray1(NO_, 4) = Parts(i,4)
SpeciesArray1(NO_, 5) = Parts(i,5)
SpeciesArray1(NO_, 6) = Parts(i,6)
SpeciesArray1(NO_, 7) = Parts(i,7)
SpeciesArray1(NO_, 8) = Parts(i,8) NO_ = NO_ + 1
ElseIf Parts(i, flag) = "" And Parts(i, 8)="BOT" Then
SpeciesArray2(NO_, 1) = Parts(i, 1)
SpeciesArray2(NO_, 2) = Parts(i, 2)
SpeciesArray2(NO_, 3) = Parts(i,3)
SpeciesArray2(NO_, 4) = Parts(i,4)
SpeciesArray2(NO_, 5) = Parts(i, 5)
SpeciesArray2(NO_, 6) = Parts(i, 6)
SpeciesArray2(NO_, 7) = Parts(i, 7)
SpeciesArray2(NO_, 8) = Parts(i, 8)
NO_ = NO_ + 1
End If
Next i
OutCell "TOP"
Print #1
For i = 1 To UBound(SpeciesArray1, 1)
If SpeciesArray1(i, 8)="TOP" Then
For j =1 To 8
OutCell SpeciesArray1(i,j)
Next j
Print #1
End If
Next i
OutCell "BOT"
Print #1
For i = 1 To UBound(SpeciesArray2, 1)
If SpeciesArray2(i, 8)="BOT" Then
For j =1 To 8
OutCell SpeciesArray2(i,j)
Next j
Print #1
End If
Next i
Close #1
ExportToExcel
End Sub
Function AttrVal (obj As Object, nm As String)
AttrVal = IIf(obj.Attributes(nm) Is Nothing, "", obj.Attributes(nm))
End Function
Sub ExportToExcel
FillClipboard
Dim xl As Object
On Error Resume Next
Set xl =GetObject(,"Excel.Application")
On Error GoTo ExcelError' Enable error trapping.
If xl Is Nothing Then
Set xl =CreateObject("Excel.Application")
End If
xl.Visible = True
xl.Workbooks.Add
xl.ActiveSheet.Paste
xl.Range("A1:H1").Font.Bold = True
xl.Range("A1:H1").NumberFormat = "@"
xl.Range("A1:H1").AutoFilter
For i = 0 To UBound(Align)
xl.Columns(i + 1).HorizontalAlignment = Choose(Align(i)+1, -4131, -4152, -4108)
Next
xl.ActiveSheet.UsedRange.Columns.AutoFit
'Output Report Header
xl.Rows(1).Insert
xl.Rows(1).Cells(1) = Space(1) & "Part Report for " & fname & " on " & Now
xl.Rows(2).Insert
xl.Rows(1).Font.bold = True
'Output Design Totals
lastRow = xl.ActiveSheet.UsedRange.Rows.Count + 1
xl.Rows(lastRow + 1).Font.bold = True
xl.Rows(lastRow + 1).Cells(1) = Space(1) & "Design Part count: " & ActiveDocument.Components.Count
xl.Range("A1").Select
On Error GoTo 0 ' Disable error trapping.
Exit Sub
ExcelError:
MsgBox Err.Description, vbExclamation, "Error Running Excel"
On Error GoTo 0 ' Disable error trapping.
Exit Sub
End Sub
Sub OutCell (txt As String)
Print #1, txt; vbTab;
End Sub
Sub FillClipboard
StatusBarText = "Export Data To Clipboard..."
' Load whole file to string variable
tempFile = DefaultFilePath & " emp.txt"
Open tempFileFor Input As #1
L = LOF(1)
AllData$ = Input$(L,1)
Close #1
'Copy whole data to clipboard
Clipboard AllData$
Kill tempFile
StatusBarText = ""
End Sub
通過以上代碼,我們成功實現了在PADS導出BOM時區分頂層和底層元器件的功能。使用這個區分頂層和底層的BOM,工程師可以更好地進行設計分析、成本估算以及供應鏈管理,提高工作效率和準確性。
總結起來,本文介紹了如何通過修改PADS導出BOM的腳本,實現區分頂層和底層元器件的功能。通過這樣的改進,我們可以更好地對電路板中的元器件進行分類和統計,提高設計過程的可視性和管理效果。希望這篇文章對您在設計PCB時的工作有所幫助。
-
元器件
+關注
關注
112文章
4725瀏覽量
92477 -
PADS
+關注
關注
80文章
808瀏覽量
107829 -
BOM
+關注
關注
5文章
256瀏覽量
40221
原文標題:如何實現PADS導出區分頂層和底層元器件的BOM
文章出處:【微信號:電子設計聯盟,微信公眾號:電子設計聯盟】歡迎添加關注!文章轉載請注明出處。
發布評論請先 登錄
相關推薦
評論