Pads/Powerpcb 将BOM中的元件值导入到PCB文件中

2019-07-14 12:24发布

这段代码是将文件文件"reflist.txt"中的元件值导入到pcb文件中的元件属性中,使用操作步骤: 1. 将代码复制到文本文件中,保存为loadBomValue2PCB.bas后缀的文件 2.更改代码中文件目录或者按代码创建对应目录 logfile="D:padsScriptloadtextbom.log" 此为程序运行生成的日志文件 inputfile="D:padsScript eflist.txt" 此为输入文件,一个元件一行,每行的格式为(不含引号):"元件位置 元件值", 表示Tab为分隔符3.打开PCB文件,在Tool - Basic Scripts - Basic Scripts 中加载刚刚保存的.bas文件,运行即可.使用前请先备份当前PCB文件,以免意外. 4.导入完成后,元件的属性会增加BOMValue这项,reflist中没有的元件,此项值为"xxx",表示不贴

Sub Main Dim comps As Object Dim refline As String Dim position As Integer Dim compname As String Dim bomvalue As String Dim inputfile As String Dim logfile As String Dim t As String t=Chr$(9) logfile="D:padsScriptloadtextbom.log" inputfile="D:padsScript eflist.txt" Open inputfile For Input As #1 Open logfile For Output As #2 '先把所有元件增加BOMValue属性,并设为"xxx" For Each comps In ActiveDocument.Components If comps.Attributes("BOMValue") Is Nothing Then 'comps.Attributes.Add("BOMValue", "BomNC") comps.Attributes.Add("BOMValue", "xxx") Else 'comps.Attributes("BOMValue")="BomNC" comps.Attributes("BOMValue")="xxx" End If Next comps Do While Not EOF(1) Line Input #1, refline 'Text of this line will be stored in variable TextLine If refline="" Then GoTo fileclose position=InStr(refline,t) compname=Left(refline,position-1) bomvalue=Right(refline,Len(refline)-position) '遇到空行,即停止,所以内容中间不能有空行  If compname="" Then GoTo fileclose Print #2, compname On Error GoTo errprocess Set comps=ActiveDocument.GetObjects(ppcbObjectTypeComponent,compname,0) If comps.Count=0 Then Print #2, "Error:" & compname; " is not found" GoTo linenext End If If comps(1).Attributes("BOMValue") Is Nothing Then comps(1).Attributes.Add("BOMValue", bomvalue) Else comps(1).Attributes("BOMValue")=bomvalue End If If comps(1).Attributes("Value") Is Nothing Then print #2, "Info:" & compname & t & "novalue" & t & bomvalue Else print #2, "Info:" & compname & t & comps(1).Attributes("Value") & t & bomvalue End If linenext: Loop GoTo fileclose errprocess: MsgBox(Err.Description) Print #2,Err.Description On Error GoTo 0 GoTo linenext fileclose: Close #1 Print #2,"last comp: " & compname Close #2 On Error GoTo openerror '运行结束会打开日志文件,请注意文件中是否有Error,即清单中的元件无法在PCB中找到的情况 Shell "notepad.exe " &logfile,1 Exit Sub openerror: MsgBox(Err.Description + logfile) End Sub