|
经典图书 其实代码都是差不多,只是方法不一样,用GetComponents只是不用递归调用,只遍历就行。主要的是用字典存储数量信息,第一次遍历存储统计的数量信息,第二次遍历将统计的数量写入模型。因本人不会VBA所以只能提供VB.NET代码,此代码不完整,仅供参考:
'统计数量
For i = 0 To swChidren.Length - 1
swCom = swChidren(i)
If swCom.IsVirtual Then
Continue For
End If
If swCom.IsSuppressed Then
Continue For
End If
If swCom.ExcludeFromBOM Then
Continue For
End If
swGetPathName = swCom.GetPathName.ToUpper
swcomKey = swComDict.ContainsKey(swGetPathName)
If swcomKey = False Then
'TextBox1.AppendText(vbCrLf & swGetPathName)
swComDict.Add(swGetPathName, swComtmp)
Else
swComtmps = swComDict.Item(swGetPathName) + 1
swComDict.Item(swGetPathName) = swComtmps
End If
Next
'写入数量
For j = 0 To swChidren.Length - 1
swCom = swChidren(j)
If swCom.IsVirtual Then
Continue For
End If
If swCom.IsSuppressed Then
Continue For
End If
If swCom.ExcludeFromBOM Then
Continue For
End If
Dim swToNama As String
Dim swTopDocName As String
Dim swReplaceName As String
Dim swTopPCode As String
Dim swTopPName As String
Dim swConfigName As String
swConfigName = swCom.ReferencedConfiguration
swGetPathName = swCom.GetPathName.ToUpper
swPathSplit = Split(swGetPathName, "")
swToNama = swPathSplit(UBound(swPathSplit))
swTopDocName = Microsoft.VisualBasic.Left(swToNama, Len(swToNama) - 7)
Label1.Text = "打开模型:"
Label12.Text = swGetPathName
swContains = swMocName.Contains(swGetPathName)
If swContains = True Then
Continue For
Else
curNode = rootNode.Nodes.Add(swTopDocName)
swcomModel = swCom.GetModelDoc2
swMocName.Add(swGetPathName)
swComtmpa = swComDict.Item(swGetPathName)
If RadioButton3.Checked = True Then
swPropMgr = swcomModel.Extension.CustomPropertyManager("")
Else
swPropMgr = swcomModel.Extension.CustomPropertyManager(swConfigName)
End If
If RadioButton7.Checked = True Then
swPropMgr.Add3(CustomInfoQTY, 30, swComtmpa, 1)
If RadioButton11.Checked = True Then
swPropMgr.Add3(CustomInfoTTY, 30, Couu, 1)
End If
End If
End If
swcomModel.Save()
Next
复制代码 |
|