導(dǎo)出BOM是硬件工程師在設(shè)計(jì)PCB時(shí)必備的一項(xiàng)任務(wù)。通常情況下,導(dǎo)出的BOM中并沒有區(qū)分頂層和底層的元器件,但是有時(shí)候我們需要對(duì)這兩者進(jìn)行分開,以便更好地進(jìn)行統(tǒng)計(jì)和管理。
本文將介紹如何通過編寫PADS的BOM的導(dǎo)出腳本代碼實(shí)現(xiàn)這個(gè)功能。
首先,我們需要了解腳本中的原理。在PADS導(dǎo)出BOM的腳本中,一般會(huì)讀取元器件的相關(guān)信息,如元器件編號(hào)、名稱、數(shù)量等。我們需要在腳本中增加元器件層信息的讀取,以及在整理元器件時(shí)對(duì)層信息進(jìn)行判斷,從而實(shí)現(xiàn)元器件分頂層和底層的歸類統(tǒng)計(jì)。
編寫以下代碼:
代參考代碼:
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
通過以上代碼,我們成功實(shí)現(xiàn)了在PADS導(dǎo)出BOM時(shí)區(qū)分頂層和底層元器件的功能。使用這個(gè)區(qū)分頂層和底層的BOM,工程師可以更好地進(jìn)行設(shè)計(jì)分析、成本估算以及供應(yīng)鏈管理,提高工作效率和準(zhǔn)確性。
總結(jié)起來,本文介紹了如何通過修改PADS導(dǎo)出BOM的腳本,實(shí)現(xiàn)區(qū)分頂層和底層元器件的功能。通過這樣的改進(jìn),我們可以更好地對(duì)電路板中的元器件進(jìn)行分類和統(tǒng)計(jì),提高設(shè)計(jì)過程的可視性和管理效果。希望這篇文章對(duì)您在設(shè)計(jì)PCB時(shí)的工作有所幫助。
-
元器件
+關(guān)注
關(guān)注
113文章
4747瀏覽量
92820 -
PADS
+關(guān)注
關(guān)注
80文章
808瀏覽量
107951 -
BOM
+關(guān)注
關(guān)注
5文章
258瀏覽量
40376
原文標(biāo)題:如何實(shí)現(xiàn)PADS導(dǎo)出區(qū)分頂層和底層元器件的BOM
文章出處:【微信號(hào):電子設(shè)計(jì)聯(lián)盟,微信公眾號(hào):電子設(shè)計(jì)聯(lián)盟】歡迎添加關(guān)注!文章轉(zhuǎn)載請(qǐng)注明出處。
發(fā)布評(píng)論請(qǐng)先 登錄
相關(guān)推薦
評(píng)論