Sub CATMain()
Rem 获取CATIA件号名称
Dim Doc1 As Object
Set Doc1 = CATIA.ActiveDocument
Dim Selection1
Set Selection1 = Doc1.Selection
Dim PartNB()
Dim m1
m1 = 0
If Selection1.Count > 0 And TypeName(Doc1) = "ProductDocument" Then
For i = 1 To Selection1.Count
Set product1 = Selection1.Item(i).Value
If product1.PartNumber <> "" Then
Dim RePart As Boolean
RePart = False
If m1 <> 0 Then
For k = 0 To m1 - 1
If PartNB(k) = product1.PartNumber Then
RePart = True
End If
Next
End If
Rem 如果不是重复文档才复制
If RePart = False Then
ReDim Preserve PartNB(m1)
PartNB(m1) = product1.PartNumber
m1 = m1 + 1
End If
End If
Next
For Each Doc In CATIA.Documents
If TypeName(Doc) = "ProductDocument" Or TypeName(Doc) = "PartDocument" Then
For j = 0 To m1 - 1
If Doc.Product.PartNumber = PartNB(j) Then
Rem 拷贝这个Doc
Copy1 Doc
End If
Next
End If
Next
ElseIf TypeName(Doc1) = "PartDocument" Then
ReDim Preserve PartNB(0)
PartNB(0) = Doc1.Product.PartNumber
Rem 拷贝单件过去
Copy1 Doc1
End If
MsgBox "执行完毕!"
End Sub
Sub Copy1(Doc)
Dim WshShell As Object, a As String
Set WshShell = CreateObject("WScript.Shell")
FileCopy Doc.Path & "\" & Doc.Name, WshShell.SpecialFolders("Desktop") & "\temp\" & Doc.Name
End Sub