Get-BomRows

This function is called recursively for loading the BOM tree.
The returned BomRow are the children of the BOMs shown in the BOM Window.

Syntax

Get-BomRows [-BomHeader] <Item>

Parameters

Type

Name

Description

input/output

Mandatory

Default value

BomRow

BomHeader

The parent element for which bom rows must be returned

input

yes

Return type

PSObject[] ← typically an array of powerVault FileBomRows or ItemBomRows or empty.
It is recommended for every BomRow to provide at least the following properties :

  • _Name ← serves as the unique identifier for every BOM and Item

  • Bom_Number

  • Bom_PositionNumber

  • Bom_Quantity

Remarks

The first time the function is called for the root entity, which is passed to the Show-BomWindow -Entity parameter.
For each returned BomRow, the function is then invoked again recursively until no more new rows are returned and the complete BOM structure is loaded.
In order to signal a leaf of the BOM tree (a BomRow that has no more children) the function should return an empty array.

Note: The function will only be called once for BOMs that are located multiple times in the BOM tree.

In general two categories of properties can be provided for all the BomRows:

  • BOM properties are properties prefixed with ‘Bom_’ (e.g. Bom_PositionNumber, Bom_Unit, …).
    They are displayed only in the BOM-Tab without the prefix.

  • Entity properties are all other properties (e.g. Description, _Category, …).
    They are available in both the BOM-Tab and the Items-Tab.

Since every BomRow is a PSObject, custom BOM properties and Entity properties can be attached and later displayed as columns in the BOM Window.

When an exception is thrown within this function, the passed $bomHeader element is marked as failed in the BOM Window.

Examples

Return a single BOM row with custom properties:

function Get-BomRows($bomHeader){
   if($bomHeader._Name -eq 'BomRow'){
      return @()
   }
   $bomRow = New-Object -TypeName PSObject -Property @{
      #Recommended properties
      _Name='BomRow'
      Bom_Quantity=10
      Bom_PositionNumber=1
      Bom_Number='BomRow'
      _Category='Part' #Additional entity property
      Bom_Unit='Each' #Additional BOM property
   }
   return @($bomRow)
}

Return all BOM rows of a Vault Item:

function Get-BomRows($vaultItem) {
   $bomRows = Get-VaultItemBom -Number $vaultItem._Number
   $bomRows | foreach {
      if($vaultItem.Bom_RowOrder) {
         Add-Member -InputObject $_ -Name Bom_RowOrder -Value ("{0}.{1}" -f $vaultItem.Bom_RowOrder,$_.Bom_RowOrder) -MemberType NoteProperty -Force
      }
   }
   return $bomRows
}

Return all BOM rows of a Vault file and warn about disabled Structured View:

function Get-BomRows($file) {
   $fileBom = Get-VaultFileBom -File $file._FullPath

   if(($fileBom | select -ExpandProperty 'Bom_PositionNumber' -Unique) -eq '') {
      throw "The BOM of file '$($file._Name)' contains $($fileBom.Count) rows without position number! Please checkout the file in Inventor, enable the Structured View and re-checkin the file to Vault!"
   }
   return $fileBom
}

Return all BOM rows of a Vault Item or File, by handling purchased, virtual and non-master model state components:

function Get-BomRows($bomHeader) {
   if($bomHeader._EntityTypeID -notin 'ITEM','FILE') {        
      return @()    
   }
   if($bomHeader._EntityTypeID -eq "ITEM") {
      $bomRows = Get-VaultItemBom -Number $bomHeader._Number
   }
   if($bomHeader._EntityTypeID -eq "FILE") {
      if($bomHeader.Bom_Structure -eq 'Purchased') {
         return @()
      }
      $bomRows = Get-VaultFileBom -File $bomHeader._FullPath -ModelStateType $bomHeader.Bom_ModelState
   }

   foreach($bomRow in $bomRows) {
      if($null -eq $bomRow._EntityTypeID) {
         # Virtual components - have no file properties
         Add-Member -InputObject $bomRow -Name "BomType" -Value "Virtual" -MemberType NoteProperty -Force
      }       
      if($bomHeader.Bom_RowOrder) { 
         Add-Member -InputObject $bomRow -Name Bom_RowOrder -Value ("{0}.{1}" -f $bomHeader.Bom_RowOrder,$bomRow.Bom_RowOrder) -MemberType NoteProperty -Force        
      }
   }
   return $bomRows
}