Hi:
I have a VBS code which can run in expedition.but i write the code using VB.NET. there are error about "item" property.
can you help me? thanks
vbs code:
dim result1:result1=""
'Set the unit to be used
pcbDocObj.CurrentUnit = epcbUnitMM
'Creat file to save check result
Dim overWriteInt: overWriteInt = 1
' Create a FileSystemObject
Dim fileSysObj
Set fileSysObj = CreateObject("Scripting.FileSystemObject")
Dim txtStreamObj
Set txtStreamObj = fileSysObj.CreateTextFile(pcbDocObj.Path & _
"LogFiles/Component and Component Report.txt", overWriteInt)
dim i,j
' Add a header
txtStreamObj.WriteLine()
txtStreamObj.WriteLine("component and component distance Report : " &Date&" "&time)
txtStreamObj.WriteLine()
'Collect component information
Dim cmpsTopColl,cmpTopObj
Set cmpsTopColl = pcbDocObj.Components(epcbSelectAll,epcbCompGeneral,epcbCelltypePackage,"*")
cmpsTopColl.Sort
'check clearance between top component and component
for i = 1 to (cmpsTopColl.count -1)
for j = (i+1) to (cmpsTopColl.count)
if cmpsTopColl.item(i).Side = cmpsTopColl.item(j).Side then
'clearance between component and component PlaceMinBot10mils
if pcbdocobj.clearance.getactualminclearance(cmpsTopColl.item(i),cmpsTopColl.item(j))<0.254 then
result1 = result1 & " " & cmpsTopColl.item(i).refdes & " and "&cmpsTopColl.item(j).refdes &" distance < 10mil"& vbCrLf
txtStreamObj.Write(cmpsTopColl.item(i).refdes & "and"&cmpsTopColl.item(j).refdes &" distance is "&pcbdocobj.clearance.getactualminclearance(cmpsTopColl.item(i),cmpsTopColl.item(j))&"mm"&"----"&"Spec is 10mil")
txtStreamObj.WriteLine()
end if
End if
Next
Next
' Close the file
txtStreamObj.Close()
if result1="" then
msgbox("Don't need to check the distance between component and component.")
else
msgbox("Take care of: "& vbCrLf&result1)
end if
VB.net Code (VS2010):
Sub CheckComponent2ComponentDistance()
lsbResult.Items.Clear()
Call MGCPCB_Connect()
Const epcbUnitMM As MGCPCB.EPcbUnit = 4
Const epcbSelectAll As MGCPCB.EPcbSelectionType = 0
Const epcbCompGeneral As MGCPCB.EPcbComponentType = 4
Const epcbCelltypePackage As MGCPCB.EPcbCelltype = 4
Const vbCrLf1 As String = vbCrLf
Dim result1 As String
result1 = ""
'Set the unit to be used
pcbDoc.CurrentUnit = epcbUnitMM
'Creat file to save check result
Dim overWriteInt As Integer
overWriteInt = 1
' Create a FileSystemObject
Dim fileSysObj As Object
fileSysObj = CreateObject("Scripting.FileSystemObject")
Dim txtStreamObj As Object
txtStreamObj = fileSysObj.CreateTextFile(pcbDoc.Path & _
"LogFiles/Component and Component Report.txt", overWriteInt)
Dim i, j, num As Integer
i = 0
j = 0
' Add a header
txtStreamObj.WriteLine()
txtStreamObj.WriteLine("component and component distance Report : ")
txtStreamObj.WriteLine()
'Collect component information
Dim cmpsColl, comp1Obj, comp2Obj As Object
cmpsColl = pcbDoc.Components(epcbSelectAll, epcbCompGeneral, epcbCelltypePackage, "*")
'cmpsColl.Sort()
'cmpsColl.Highlighted = True
'num = cmpsColl.Count
'check clearance between top component and component
For i = cmpsColl.Count To 2 Step -1
comp1Obj = cmpsColl.Item(i)
MsgBox(comp1Obj.Side)
For j = (i - 1) To 1 Step -1
comp2Obj = cmpsColl.Item(j)
If cmpsColl.Item(i) Is Nothing Or comp2Obj Is Nothing Then
'MsgBox("t")
Else
If comp1Obj.Side = comp2Obj.Side Then
'clearance between component and component PlaceMinBot10mils
If pcbDoc.Clearance.GetActualMinClearance(comp1Obj, comp2Obj) < 0.254 Then
result1 = result1 & " " & comp1Obj.refdes & " and " & comp2Obj.refdes & " distance < 10mil" & vbCrLf
lsbResult.Items.Add(comp1Obj.refdes & " and " & comp2Obj.refdes & " distance < 10mil")
txtStreamObj.Write(comp1Obj.refdes & "and" & comp2Obj.refdes & " distance is " & pcbDoc.Clearance.GetActualMinClearance(comp1Obj, comp2Obj) & "mm" & "----" & "Spec is 10mil")
txtStreamObj.WriteLine()
End If
End If
End If
Next
Next
' Close the file
txtStreamObj.Close()
If result1 = "" Then
MsgBox("Don't need to check the distance between component and component.")
Else
MsgBox("Take care of: " & vbCrLf1 & result1)
End If
Call MGCPCB_Disconnect()
End Sub