我(面对我)面临一些挑战。我使用它的API为Autodesk Inventor创建了BOM导出工具。除了导出的订单被扰乱之外,这种方式有效。我已收到Autodesk的建议,要求使用解决方法,因为API不允许我按正确的顺序导出BOM。
在对这个主题发表一些评论后,我发现我的问题完全错了,所以我编辑了这个问题
1)我想要做的是创建一个BOM数组2)对它进行排序,然后3)导出到另一个程序(在我的情况下为Excel)。
1)为BOM创建一个数组
Private Sub QueryBOMRowProperties(oBOMRows As BOMRowsEnumerator, ItemTab As Long)
ItemTab = ItemTab + 3
' Iterate through the contents of the BOM Rows.
Dim i As Long
Dim oCompDef As Inventor.ComponentDefinition
Dim oItemNumber As String
Dim oDescription As Inventor.Property
Dim oQTY As Integer
Dim oMaterial As String
For i = 1 To oBOMRows.Count
' Get the current row.
Dim oRow As BOMRow
oRow = oBOMRows.Item(i)
oCompDef = oRow.ComponentDefinitions.Item(1)
oItemNumber = oRow.ItemNumber
oDescription = oCompDef.Document.PropertySets.Item("Design Tracking Properties").Item("Description")
oQTY = oRow.ItemQuantity
If TypeOf oCompDef Is PartComponentDefinition Then
Dim oPartCompDef As PartComponentDefinition
oPartCompDef = oCompDef
oMaterial = oPartCompDef.Material.Name
Else
oMaterial = ""
End If
ReDim Preserve oBOMArray(3, i)
oBOMArray(0, i) = oItemNumber
oBOMArray(1, i) = oDescription.Value
oBOMArray(2, i) = oQTY
oBOMArray(3, i) = oMaterial
Debug.Print(oBOMArray(0, i) & " | " & oBOMArray(1, i) & " | " & oBOMArray(2, i) & " | " & oBOMArray(3, i))
'Recursively iterate child rows if present.
If Not oRow.ChildRows Is Nothing Then
Call QueryBOMRowProperties(oRow.ChildRows, ItemTab)
End If
Next
ItemTab = ItemTab - 3
End Sub
这给了我这个结果,因为你可以看到itemnumbers没有很好地排序。
1 | Pipe ø88,9 x 6,3 - lg. 427mm | 1 | WN 1.4306
3 | Elbow 90deg DN80(ø88,9) x 3,2 - acc. DIN 2605 type 3 | 1 | WN 1.4306
4 | Pipe ø88,9 x 3,2 - lg. 161mm | 1 | WN 1.4306
2 | Repad ø200 x 12mm (Plate 201 x 200) | 1 | WN 1.4307
6 | Hex Head Plug 1/4in - acc. ASME B16.11 | 1 | A2
5 | Plate ø110 x 5mm | 1 | WN 1.4307
7 | "C-BW-2" : Buttweld nozzle | 1 |
7.2 | Pipe ø88,9 x 6,3 - lg. 427mm | 1 | WN 1.4306
7.3 | Elbow 90deg DN80(ø88,9) x 3,2 - acc. DIN 2605 type 3 | 1 | WN 1.4306
7.4 | Repad ø200 x 12mm (Plate 201 x 200) | 1 | WN 1.4307
7.5 | Hex Head Plug 1/4in - acc. ASME B16.11 | 1 | A2
7.1 | Plate ø110 x 5mm | 1 | WN 1.4307
2)对Itemnumbers进行排序
您可以说使用IndexOf
来查找要导出的行,但这会迫使我确切地知道数组中的哪些项目数(至少我认为)
我认为我最好的机会是将物品编号分类到正确的顺序,但是有人能指出我正确的方向吗?特别是如何使用数组中的子编号执行此操作?
或者我应该看看SortedList
?
https://msdn.microsoft.com/en-us/library/system.collections.sortedlist%28v=vs.110%29.aspx
3)导出项目,只是将它们写出到Excel并在完成后清除数组。