By Wayne Brill
Here is a VB example that changes the Quantity of a BOM Row. To test this code you can add a button to this SDK sample:
C:\Program Files (x86)\Autodesk\Autodesk Vault 2016 SDK\vs12\VB\ItemEditor
After the code runs you can see the Quantity being changed in Vault Explorer. The ItemBOM and ItemAssoc are retrieved from the Item being edited.
Private Sub Button1_Click_WB(sender As Object, e As EventArgs) Handles Button1.Click
Dim parentItem As Item = m_selectedItem
'Change this to use an Item Number in your vault
Dim ChildItem As Item = m_connection.WebServiceManager.ItemService.GetLatestItemByItemNumber("100001")
Dim newQty As Integer = 2
updateBOMQuantity_WB(parentItem, ChildItem, newQty)
End Sub
Private Sub updateBOMQuantity_WB(parentItem As Item, childItem As Item, newQty As Integer)
Dim item2 As Item = Nothing
Try
item2 = m_connection.WebServiceManager.ItemService.EditItems(New Long() {m_selectedItem.RevId})(0)
Dim options As BOMViewEditOptions = BOMViewEditOptions.Defaults Or BOMViewEditOptions.ReturnOccurrences _
Or BOMViewEditOptions.ReturnExcluded Or BOMViewEditOptions.ReturnUnassignedComponents
' Get the ItemBOM from the Item being edited
Dim bom As ItemBOM = m_connection.WebServiceManager.ItemService.GetItemBOMByItemIdAndDate _
(item2.Id, DateTime.MinValue, BOMTyp.Latest, options)
' Get the ItemAssoc from the ItemBOM being edited
Dim itemAssoc2 As ItemAssoc =
bom.ItemAssocArray.FirstOrDefault(Function(x) x.CldItemMasterID = childItem.MasterId)
Dim newBomItemAssocParam2 As New ItemAssocParam
newBomItemAssocParam2.Id = itemAssoc2.Id
newBomItemAssocParam2.EditAct = BOMEditAction.Update
newBomItemAssocParam2.Quant = newQty
Dim bom2 As ItemBOM = m_connection.WebServiceManager.ItemService.UpdateItemBOMAssociations _
(item2.Id, {newBomItemAssocParam2}, BOMViewEditOptions.ReturnBOMFragmentsOnEdits)
m_connection.WebServiceManager.ItemService.UpdateAndCommitItems(New Item() {item2})
Catch ex As Exception
MsgBox(ex.Message)
m_connection.WebServiceManager.ItemService.UndoEditItems(New Long() {item2.Id})
End Try
End Sub
Dim parentItem As Item = m_selectedItem
'Change this to use an Item Number in your vault
Dim ChildItem As Item = m_connection.WebServiceManager.ItemService.GetLatestItemByItemNumber("100001")
Dim newQty As Integer = 2
updateBOMQuantity_WB(parentItem, ChildItem, newQty)
End Sub
Private Sub updateBOMQuantity_WB(parentItem As Item, childItem As Item, newQty As Integer)
Dim item2 As Item = Nothing
Try
item2 = m_connection.WebServiceManager.ItemService.EditItems(New Long() {m_selectedItem.RevId})(0)
Dim options As BOMViewEditOptions = BOMViewEditOptions.Defaults Or BOMViewEditOptions.ReturnOccurrences _
Or BOMViewEditOptions.ReturnExcluded Or BOMViewEditOptions.ReturnUnassignedComponents
' Get the ItemBOM from the Item being edited
Dim bom As ItemBOM = m_connection.WebServiceManager.ItemService.GetItemBOMByItemIdAndDate _
(item2.Id, DateTime.MinValue, BOMTyp.Latest, options)
' Get the ItemAssoc from the ItemBOM being edited
Dim itemAssoc2 As ItemAssoc =
bom.ItemAssocArray.FirstOrDefault(Function(x) x.CldItemMasterID = childItem.MasterId)
Dim newBomItemAssocParam2 As New ItemAssocParam
newBomItemAssocParam2.Id = itemAssoc2.Id
newBomItemAssocParam2.EditAct = BOMEditAction.Update
newBomItemAssocParam2.Quant = newQty
Dim bom2 As ItemBOM = m_connection.WebServiceManager.ItemService.UpdateItemBOMAssociations _
(item2.Id, {newBomItemAssocParam2}, BOMViewEditOptions.ReturnBOMFragmentsOnEdits)
m_connection.WebServiceManager.ItemService.UpdateAndCommitItems(New Item() {item2})
Catch ex As Exception
MsgBox(ex.Message)
m_connection.WebServiceManager.ItemService.UndoEditItems(New Long() {item2.Id})
End Try
End Sub