Quantcast
Channel: Manufacturing DevBlog
Viewing all articles
Browse latest Browse all 516

Edit an Item BOM Row in Vault – VB example

$
0
0

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. 

PrivateSub Button1_Click_WB(sender AsObject, e AsEventArgs) Handles Button1.Click
    Dim parentItem AsItem = m_selectedItem
    'Change this to use an Item Number in your vault
    Dim ChildItem AsItem = m_connection.WebServiceManager.ItemService.GetLatestItemByItemNumber("100001")
    Dim newQty AsInteger = 2
    updateBOMQuantity_WB(parentItem, ChildItem, newQty)
EndSub

PrivateSub updateBOMQuantity_WB(parentItem AsItem, childItem AsItem, newQty AsInteger)
    Dim item2 AsItem = Nothing
    Try
        item2 = m_connection.WebServiceManager.ItemService.EditItems(NewLong() {m_selectedItem.RevId})(0)

        Dim options AsBOMViewEditOptions = BOMViewEditOptions.Defaults OrBOMViewEditOptions.ReturnOccurrences _
                     OrBOMViewEditOptions.ReturnExcluded OrBOMViewEditOptions.ReturnUnassignedComponents

        ' Get the ItemBOM from the Item being edited
        Dim bom AsItemBOM = m_connection.WebServiceManager.ItemService.GetItemBOMByItemIdAndDate _
                                (item2.Id, DateTime.MinValue, BOMTyp.Latest, options)

        ' Get the ItemAssoc from the ItemBOM being edited
        Dim itemAssoc2 AsItemAssoc =
            bom.ItemAssocArray.FirstOrDefault(Function(x) x.CldItemMasterID = childItem.MasterId)

        Dim newBomItemAssocParam2 AsNewItemAssocParam
        newBomItemAssocParam2.Id = itemAssoc2.Id
        newBomItemAssocParam2.EditAct = BOMEditAction.Update
        newBomItemAssocParam2.Quant = newQty

        Dim bom2 AsItemBOM = m_connection.WebServiceManager.ItemService.UpdateItemBOMAssociations _
                  (item2.Id, {newBomItemAssocParam2}, BOMViewEditOptions.ReturnBOMFragmentsOnEdits)

        m_connection.WebServiceManager.ItemService.UpdateAndCommitItems(NewItem() {item2})

    Catch ex AsException
        MsgBox(ex.Message)
        m_connection.WebServiceManager.ItemService.UndoEditItems(NewLong() {item2.Id})
    EndTry
EndSub

Viewing all articles
Browse latest Browse all 516

Trending Articles