Show-BOMWindow

Opens the BOM Window for checking and transferring BOM’s and materials of Vault or .

Syntax

1
Show-BOMWindow [-Entity] <PSObject> [-NoWait] [<CommonParameters>]

Parameters

Type

Name

Description

Optional

/

Entity

The main Vault entity whose BOM will be loaded and displayed.

no

SwitchParameter

NoWait

Opens the BOM window in non-modal mode, allowing the PowerShell execution to continue without waiting for the BOM Window to close.

yes

Return type

empty ← On failure the Exception/ErrorMessage can be accessed using $Error.

Remarks

The BOM Window loads the BOM tree for the given -Entity by calling the method Get-BomRows recursively.
Such root elements must provide at least entity properties as those provided by powerVault or objects.
However also custom BOM properties, such as those available on powerVault and , can be passed and displayed as columns.

In order to customize the Check- and Transfer operations for BOMs and Items, the following functions are required and must be implemented:

By default, the BOM Window is opened in modal mode, meaning that the cmdlet executes until the BOM Window is closed.

Using the -NoWait parameter allows the PowerShell execution to continue while the BOM Window remains open. However, only a single BOM Window can be displayed at a time.

Multithreading

In this mode, the required functions run in parallel on a separate background thread within a runspace named ‘coolOrange BOM Window’.

PowerShell variables, modules, preferences and functions are automatically shared with this runspace (they are not duplicated).
Therefore, existing ERP connections (e.g. created by Connect-ERP -OnConnect ) remain available, as well as the same instances of variables (e.g. $global:ERPSettings).
However, global variables created in the BOM Window runspace are not shared with the main runspace.

To avoid threading issues:

  • Check and avoid modifying global variables accessed in both the main and BOM Window runspaces, as this can cause unexpected behavior.

  • Do not invoke shared ScriptBlocks, as they may cause hanging, deadlocks or corrupt runspaces.
    Instead, for ERP connections with Connect-ERP -OnConnect, use the add_beforeRequest({...}) and add_AfterResponse({...}) functions.

  • Do not access thread-specific PowerShell variables from the UI thread (e.g., UI controls of the “ERP BOM” tab).

To check whether a BOM Window is currently running, you can use the automatic $IsBomWindowRunning flag.

Examples

Using the BOM Window in a Vault Item Tab (modal mode):

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
Add-VaultTab -Name 'ERP BOM' -EntityType File -Action {
   param($selectedItem)

   $xamlFile = [xml](Get-Content "$PSScriptRoot\Sample.Tab-ErpBom.xaml")
   $tab_control = [Windows.Markup.XamlReader]::Load( (New-Object System.Xml.XmlNodeReader $xamlFile) )

   $tab_control.FindName('ButtonTransferBom').add_Click({
      Show-BomWindow -Entity $selectedItem
      [System.Windows.Forms.SendKeys]::SendWait('{F5}') #refresh Tab after BOM Window is closed, to display the ERP BOM changes
   }.GetNewClosure())

   $erpBom = Get-ERPObject -EntitySet 'BomHeaders' -Keys @{ Number = $selectedItem._Number } -Expand 'Children/Item'
   ...

   <# Changes to following functions are automatically reloaded, even while the BOM Window is running.
      Restarting the BOM Window is not required #>

   function global:Get-BomRows($item) {
      return (Get-VaultItemBom -Number $vaultItem._Number)
   }
   function global:Check-Items($items) {
      foreach($item in $items) {
         $item | Update-BomWindowEntity -Status 'New'
      }
   }
   function global:Transfer-Items($items) {
      foreach($item in $items) {
         $item | Update-BomWindowEntity -Status 'Identical'
      }
   }
   function global:Check-Boms($boms) {
      foreach($bom in $boms) {
         $bom | Update-BomWindowEntity -Status 'New'
      }
   }
   function global:Transfer-Boms($boms) {
      foreach($bom in $boms) {
         $bom | Update-BomWindowEntity -Status 'Identical'
      }
   }
}

Implementing and Debugging BOM Window functions for Vault Files (non-modal):

The -NoWait parameter is also ideal for development, because the BOM Window can stay open while modified Check- and Transfer- functions can simply be re-executed.
To debug them inside the Vault Client, wait for the BOM Window to appear and to the coolOrange BOM Window runspace.

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
$file = Get-VaultFile -Properties @{'File Name'='MSB-Weld.iam'}
if($file._HasModelState) {
   $allModelStates = Get-VaultFileBom -File $file._FullPath -ModelStateType All
   $file = $allModelStates | Where-Object { $_.Bom_ModelState -eq 'Face Machining + Treading' }
}

function Get-BomRows($file) {
   return (Get-VaultFileBom -File $file._FullPath)
}

Show-BomWindow -Entity $file -NoWait

<# The following functions can be executed in parallel with the BOM Window.
   Simply re-execute them after changes without restarting the BOM Window #>

function Check-Boms($boms) {
   # Runs in the 'coolOrange BOM Window' runspace

   $file # accessible and could be modified
}
function Transfer-Boms($boms) {
   $global:Test = 'Not Shared' # exists only in the 'coolOrange BOM Window' runspace
}

Force the BOM Window to be displayed in german culture:

1
2
3
4
$file= Get-VaultFile -File '$/Designs/Pad Lock/Assemblies/Catch Assembly.iam'

[CultureInfo]::DefaultThreadCurrentUICulture = [CultureInfo]::CreateSpecificCulture('de-DE')
Show-BomWindow -Entity $file -NoWait