Community
Vault Customization
Share your knowledge, ask questions, and explore popular Vault API, Data Standard, and VBA topics related to programming, creating add-ins, or working with the Vault API.
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

UpdateItemBOMAssociationProperties

2 REPLIES 2
Reply
Message 1 of 3
Rene_Gerlach
1032 Views, 2 Replies

UpdateItemBOMAssociationProperties

Can someone tell me the correct values for the AssocPropItem for this function?

2 REPLIES 2
Message 2 of 3
barbara.han
in reply to: Rene_Gerlach

VB.NET sample snippet:

    ' Get the Associatin Property Definitions

 

    Dim definitions() As AssocPropDef = m_serviceManager.PropertyService.

      GetAssociationPropertyDefinitionsByType(AssociationPropClass.ItemBOMLink)

 

    Dim definition As AssocPropDef = definitions.FirstOrDefault(Function(p) p.DispName.Equals("Test"))

    If definition Is Nothing Then

      Dim definitionInfo As AssocPropDefInfo = m_serviceManager.PropertyService.

        AddAssociationPropertyDefinition(Guid.NewGuid.ToString("D").ToLower, "Test",

                                         DataType.String, True, Nothing, Nothing,

                                         AssocPropTyp.ItemBOMAssoc)

      definition = definitionInfo.PropDef

    End If

 

    ' Set up the Association Property array to add to the specific item BOM

 

    Dim itemBOM As ItemBOM = m_serviceManager.ItemService.GetItemBOMByItemIdAndDate(

      m_selectedItem.Id, m_selectedItem.EffEnd, BOMTyp.Tip, BOMViewEditOptions.Defaults)

    Dim ParIds As List(Of Long) = New List(Of Long)

    Dim associations AsList(OfAssocPropItem) = NewList(OfAssocPropItem)

    Dim ChildIds As List(Of Long) = New List(Of Long)

 

    For Each itemAss As ItemAssoc In itemBOM.ItemAssocArray

      ParIds.Add(itemAss.ParItemID)

      ChildIds.Add(itemAss.CldItemMasterID)

      Dim association As AssocPropItem = New AssocPropItem With {

         .AssocPropTyp = AssocPropTyp.ItemBOMAssoc,

         .FromId = itemAss.ParItemID,

         .ToId = itemAss.CldItemMasterID,

         .PropDefId = definition.Id,

         .Val = "ABC",

      .ValTyp = DataType.String

      }

      associations.Add(association)

    Next

 

    ' Update item BOM association properties

 

    m_serviceManager.ItemService.UpdateItemBOMAssociationProperties(associations.ToArray(), Nothing)

 

    ' Get the item BOM association properties

 

    Dim PropIds As List(Of Long) = New List(Of Long)

    PropIds.Add(definition.Id)

    Dim assocProps() As AssocPropItem = m_serviceManager.ItemService.GetItemBOMAssociationProperties(

      ParIds.ToArray(), PropIds.ToArray(), ChildIds.ToArray())

 

C# sample snippet:

try

{

    IWebServiceCredentials credentials = new UserPasswordCredentials(

        "localhost", "Vault", "Administrator", "");

 

    using (WebServiceManager serviceMgr = new WebServiceManager(credentials))

    {

        AssocPropDef[] definitions = serviceMgr.PropertyService.

            GetAssociationPropertyDefinitionsByType(AssociationPropClass.ItemBOMLink);

        AssocPropDef definition = definitions.FirstOrDefault(p => p.DispName.Equals("Test"));

 

        if (definition == null)

        {

            AssocPropDefInfo definitionInfo = serviceMgr.PropertyService.

                AddAssociationPropertyDefinition(Guid.NewGuid().ToString("D").ToLower(),

                "Test", DataType.String, true, null, null, AssocPropTyp.ItemBOMAssoc);

 

            definition = definitionInfo.PropDef;

        }

        Item parentItem = serviceMgr.ItemService.

            GetLatestItemByItemNumber("100003"), 

            childItem = serviceMgr.ItemService.GetLatestItemByItemNumber("100013");

 

        AssocPropItem association = new AssocPropItem()

        {

            AssocPropTyp = AssocPropTyp.ItemBOMAssoc,

            FromId = parentItem.Id,

            ToId = childItem.MasterId,

            PropDefId = definition.Id,

            Val = "ABC",

            ValTyp = DataType.String,

        };

 

        serviceMgr.ItemService.UpdateItemBOMAssociationProperties(

            new AssocPropItem[] { association }, null);

    }

}

catch (Exception ex)

{

    Console.WriteLine("ERROR: " + ex.Message);

}

Barbara Han
Developer Technical Services
Autodesk Developer Network
Message 3 of 3
marco_lorenz1
in reply to: barbara.han

Hello, Barbara,

 

the example does not work with current versions - could you please provide an example working with 2017?

Thanks!


Marco

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Autodesk Design & Make Report