Message 1 of 10
Help with SDK's Using the BOM APIs API Sample - ordering
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
I've written code based on this. It's pretty much verbatim.
Public Sub CreateNewShiplist() ' Set a reference to the assembly document. ' This assumes an assembly document is active. Dim oDoc As AssemblyDocument Set oDoc = ThisApplication.ActiveDocument ' Make sure that the structured view is enabled. Dim TopLevelOnly As Boolean If MsgBox("Do you want create a shipping list just the top level assembly?", vbYesNo) = vbYes Then TopLevelOnly = True Else TopLevelOnly = False End If ' Set a reference to the BOM Dim oBOM As BOM Set oBOM = oDoc.ComponentDefinition.BOM ' Set to do correct levels If TopLevelOnly Then oBOM.StructuredViewFirstLevelOnly = True Else oBOM.StructuredViewFirstLevelOnly = False End If oBOM.StructuredViewEnabled = True 'Set a reference to the "Structured" BOMView Dim oBOMView As BOMView Set oBOMView = oBOM.BOMViews.Item("Structured") 'Initialize the tab for ItemNumber Dim ItemTab As Long ItemTab = -3 MyCount = 0 SL_Text = "" Call QueryBOMRowProperties(oBOMView.BOMRows, ItemTab) 'Debug.Print SL_Text CreateShiplist (SL_Text) End Sub Private Sub QueryBOMRowProperties(oBOMRows As BOMRowsEnumerator, ItemTab As Long) Dim PartInfo As String Dim AddBox As Boolean Dim Tag As String AddBox = False ItemTab = ItemTab + 3 ' Iterate through the contents of the BOM Rows. Dim i As Long For i = 1 To oBOMRows.Count ' Get the current row. Dim oRow As BOMRow Set oRow = oBOMRows.Item(i) 'Set a reference to the primary ComponentDefinition of the row Dim oCompDef As ComponentDefinition Set oCompDef = oRow.ComponentDefinitions.Item(1) Dim oPartNumProperty As Property Dim oDescripProperty As Property Dim oTagProperty As Property If TypeOf oCompDef Is VirtualComponentDefinition Then 'Get the file property that contains the "Part Number" 'The file property is obtained from the virtual component definition Set oPartNumProperty = oCompDef.PropertySets _ .Item("Design Tracking Properties").Item("Part Number") 'Get the file property that contains the "Description" Set oDescripProperty = oCompDef.PropertySets _ .Item("Design Tracking Properties").Item("Description") On Error Resume Next Set oTagProperty = oCompDef.PropertySets _ .Item("User Defined Properties").Item("TAG_NO") If Err.Number <> 0 Then Tag = "" Else Tag = oTagProperty.Value End If PartInfo = "Part Number: " & oPartNumProperty.Value & vbCrLf PartInfo = PartInfo & " Mark No: " & Tag & vbCrLf PartInfo = PartInfo & " Description: " & oDescripProperty.Value & vbCrLf PartInfo = PartInfo & " Qty: " & oRow.ItemQuantity If MsgBox("Do you want to add the following part to the Ship List?" & vbCrLf & vbCrLf & PartInfo, vbYesNo) = vbYes Then AddBox = True Else AddBox = False End If If AddBox = True Then 'If Len(oTagProperty.Value) > 0 Then 'Debug.Print Tab(0); Tag; Tab(20); oDescripProperty.Value; Tab(90); oPartNumProperty.Value; Tab(110); oRow.ItemQuantity; Tab(120); MyCount; SL_Text = SL_Text & Tag & "|" & oDescripProperty.Value & "|" & oPartNumProperty.Value & "|" & oRow.ItemQuantity & vbCrLf End If Else 'Get the file property that contains the "Part Number" 'The file property is obtained from the parent 'document of the associated ComponentDefinition. Set oPartNumProperty = oCompDef.Document.PropertySets _ .Item("Design Tracking Properties").Item("Part Number") 'Get the file property that contains the "Description" Set oDescripProperty = oCompDef.Document.PropertySets _ .Item("Design Tracking Properties").Item("Description") On Error Resume Next Set oTagProperty = oCompDef.Document.PropertySets _ .Item("User Defined Properties").Item("TAG_NO") If Err.Number <> 0 Then Tag = "" Else Tag = oTagProperty.Value End If PartInfo = "Part Number: " & oPartNumProperty.Value & vbCrLf PartInfo = PartInfo & " Mark No: " & Tag & vbCrLf PartInfo = PartInfo & " Description: " & oDescripProperty.Value & vbCrLf PartInfo = PartInfo & " Qty: " & oRow.ItemQuantity If MsgBox("Do you want to add the following part to the Ship List?" & vbCrLf & vbCrLf & PartInfo, vbYesNo) = vbYes Then AddBox = True Else AddBox = False Exit Sub End If If AddBox Then 'Debug.Print Tab(0); Tag; Tab(20); oDescripProperty.Value; Tab(90); oPartNumProperty.Value; Tab(110); oRow.ItemQuantity; Tab(120); MyCount; SL_Text = SL_Text & Tag & "|" & oDescripProperty.Value & "|" & oPartNumProperty.Value & "|" & oRow.ItemQuantity & vbCrLf 'MsgBox SL_Text End If 'Recursively iterate child rows if present. If Not oRow.ChildRows Is Nothing Then Dim CheckSA As Boolean If MsgBox("Do you want to seach the following sub assembly for the Ship List?" & vbCrLf & vbCrLf & PartInfo, vbYesNo) = vbYes Then Call QueryBOMRowProperties(oRow.ChildRows, ItemTab) End If End If End If Next ItemTab = ItemTab - 3 End Sub
Anyhow, it seems that when it's run, it's pulling it's order from the Model Data tab and not the Structured tab as the sample code implies that it does.
Is there anything that can be done to make it get the order based on the structured tab instead?
Thanks
Mike