如上图所示,图中PCB的元器件的编号还没有摆放好,看起来很乱。如何快速将元器件编号摆放好?可以编写一个脚本,一键就能快速摆放好。
首先,打开PCB脚本编辑器,编写以下脚本。
参考代码:
Sub Main
Dim partFi As Double
Dim DocumentUnit,x As Integer
DocumentUnit = ActiveDocument.unit
ActiveDocument.unit = ppcbUnitMils
For Each part In ActiveDocument.Components
If part.Labels.Count > 0 Then
If GetPartType(part) = "CON" Or GetPartType(part) = "J" Then
For x = 1 To part.Labels.Count
If part.Labels(x)="Ref.Des." Then
partFi = (((part.PositionX-part.Pins(1).PositionX)^2) ((part.PositionY-part.Pins(1).PositionY)^2) ((part.PositionX-part.Pins(part.Pins.Count).PositionX)^2) ((part.PositionY-part.Pins(part.Pins.Count).PositionY)^2))/2
If partFi<= 5000 Then
part.Labels(x).Height=47
part.Labels(x).LineWidth=4
ElseIf PartFi <= 10000 And PartFi > 5000 Then
part.Labels(x).Height=47
part.Labels(x).LineWidth=4
ElseIf PartFi <= 30000 And PartFi > 10000 Then
part.Labels(x).Height=47
part.Labels(x).LineWidth=4
ElseIf PartFi > 30000 Then
part.Labels(x).Height=47
part.Labels(x).LineWidth=4
End If
part.Labels(x).RightReading = ppcbRightReadingOrthogonal
part.Labels(x).HorzJustification = ppcbJustifyHCenter
part.Labels(x).VertJustification = ppcbJustifyHCenter
If part.Pins.Count > 30 Then
part.Labels(x).PositionX = ( part.Pins(1).PositionX part.Pins(part.Pins.Count).PositionX)/2
part.Labels(x).PositionY = ( part.Pins(1).PositionY part.Pins(part.Pins.Count).PositionY)/2
Else
part.Labels(x).PositionX = part.PositionX
part.Labels(x).PositionY = part.PositionY
End If
End If
If part.Pins(1).PositionX = part.Pins(2).PositionX Then part.Labels(x).Orientation=90
If part.Pins(1).PositionY = part.Pins(2).PositionY Then part.Labels(x).Orientation=0
Next x
Else
For x = 1 To part.Labels.Count
If part.Labels(x)="Ref.Des." Then
'MsgBox part.Pins.Count &", " & part.Pins(1).PositionX &", " & part.Pins(1).PositionY &", " & part.Pins(2).PositionX &", " & part.Pins(2).PositionY &", " & part.Orientation &", " & part.Labels(x).Orientation
If GetPartType(part) = "U" Then
partFi = (((part.PositionX-part.Pins(1).PositionX)^2) ((part.PositionY-part.Pins(1).PositionY)^2) ((part.PositionX-part.Pins(part.Pins.Count).PositionX)^2) ((part.PositionY-part.Pins(part.Pins.Count).PositionY)^2))/2
If PartFi <= 5000 Then
part.Labels(x).Height=47
part.Labels(x).LineWidth=4
ElseIf PartFi <= 10000 And PartFi > 5000 Then
part.Labels(x).Height=47
part.Labels(x).LineWidth=4
ElseIf PartFi <= 30000 And PartFi > 10000 Then
part.Labels(x).Height=47
part.Labels(x).LineWidth=4
ElseIf PartFi > 30000 Then
part.Labels(x).Height=47
part.Labels(x).LineWidth=4
End If
Else
part.Labels(x).Height=47
part.Labels(x).LineWidth=4
End If
part.Labels(x).PositionX = part.CenterX-1
part.Labels(x).PositionY = part.CenterY-0.5
part.Labels(x).HorzJustification = ppcbJustifyHCenter
part.Labels(x).VertJustification = ppcbJustifyHCenter
part.Labels(x).RightReading = ppcbRightReadingOrthogonal
If part.Pins.Count = 2 Then
If part.Pins(1).PositionX = part.Pins(2).PositionX Then part.Labels(x).Orientation=90
If part.Pins(1).PositionY = part.Pins(2).PositionY Then part.Labels(x).Orientation=0
Else
part.Labels(x).Orientation=0
End If
End If
Next x
End If
End If
Next part
ActiveDocument.unit = DocumentUnit
End Sub
Function GetPartType(ObjName As String)
Dim x As Integer
Dim Str1 As String
y=0
If ObjName= "" Then
PartTypeName=""
Exit Function
End If
For x=1 To 3
str1=Mid(ObjName,x,1)
If 64<Asc(str1) And Asc(str1)<91 Then
y=y 1
Else
x=3
End If
Next x
GetPartType = Mid(ObjName,1,y)
End Function
然后,运行脚本,元器件的编号马上就被摆放好。
Copyright © 2024 妖气游戏网 www.17u1u.com All Rights Reserved