PCB设计完成后,如果我们要统计过孔数量,查看过孔信息怎么弄呢?可以利用脚本的方法,把PCB钻孔的信息打印出来。
首先,打开PCB脚本编辑器,编写以下代码。
参考代码如下:
Dim DrillCount As Long
Sub Main
Randomize
filename = DefaultFilePath & " mp" & CInt(Rnd()*10000) & ".txt"
Open filename For Output As #1
Print #1, "Type";Space(9);
Print #1, "Name";Space(26);
Print #1, "Net";Space(28);
Print #1, "Drill";Space(25);
Print #1, "Plated";Space(2);
Print #1, "X";Space(29);
Print #1, "Y";Space(0)
DrillCount = 0
' Lock server to speed up process
LockServer
' Go through each via in the design and output values
For Each nextVia In ActiveDocument.Vias
' Output Via Type Property
a = "Via"
Print #1, a; Space$(13-Len(a));
' Output Via Name Property
a = nextVia.Type
Print #1, a; Space$(30-Len(a));
' Output Via Attached Net Property
Set nnet = nextVia.Net
If (nnet Is Nothing) Then a = "N/A" Else a = nnet.Name
Print #1, a; Space$(30-Len(a));
' Output Via Drill Size Property
a = nextVia.DrillSize
Print #1, a; Space$(30-Len(a));
' Output Via Plated Property
a = nextVia.Plated
Print #1, a; Space$(8-Len(a));
' Output Via PositionX Property
a = Format$(nextVia.PositionX, "#.00")
Print #1, a; Space$(30-Len(a));
' Output Via PositionY Property
a = Format$(nextVia.PositionY, "#.00")
Print #1, a
DrillCount = DrillCount + 1
Next nextVia
' Unlock the server
UnlockServer
' Close the text file
Close #1
If DrillCount = 0 Then
MsgBox "The design has no drills"
Exit Sub
End If
' Start Excel and loads the text file
On Error GoTo noExcel
Dim excelApp As Object
Set excelApp = CreateObject("Excel.Application")
On Error GoTo 0
excelApp.Visible = True
excelApp.Workbooks.OpenText FileName:= filename
excelApp.Rows("1:1").Select
With excelApp.Selection
.Font.Bold = True
.Font.Italic = True
End With
excelApp.Cells.Select
excelApp.Selection.Sort Key1:=excelApp.ActiveSheet.Columns("D"), Order1:=1, Header:=0
excelApp.Selection.Subtotal GroupBy:=4, Function:=-4112, TotalList:=Array(5), Replace:=True
excelApp.ActiveSheet.Outline.ShowLevels RowLevels:=2
excelApp.Range("A1").Select
Set excelApp = Nothing
End
noExcel:
' Display the text file
Shell "Notepad " & filename, 3
End Sub
然后,运行脚本,PCB的过孔信息就被打印出来了。
由上图可以知道,过孔的类型,大小,坐标都打印出来,数量也统计出来了。
最后,保存脚本,方便以后调用。
感兴趣的朋友,可以敲写以上代码调试使用,也可以到群里下载脚本,直接使用。
编辑:hfy
-
PCB设计
+关注
关注
394文章
4670浏览量
85253
发布评论请先 登录
相关推荐
评论