CAD BOM via powerVault

2017-03-03_09-05-19Some versions ago, the CAD BOM tab have been added to Vault Data Standard. Great stuff, as it gives you the ability to view the CAD BOM without the need of items. So, it’s great for Vault Workgroup customers and for Vault Professional. The tab reads the data from the so-called file BOM blob. It’s a property at the file that contains all the CAD BOM information. Such property is automatically filled when you check-in a CAD file. You can read the content of such property via the Vault API DocumentService.GetBOMByFileId. The object provided by this API is quite complex. It contains the structured BOM, the parts only, information about purchased part, phantom assemblies, external references, virtual components, and all the other beauty of a CAD BOM.

The implementation of the CAD BOM tab is just handling basic stuff. If the BOM contains data beyond simple components, the result is either wrong or empty. We spent quite some time over the past years interpreting the BOM blob object in Vault, and implemented the logic within powerVault in the Get-VaultFileBOM command-let. Such command-let gives you in a super simple way the correct structured CAD BOM. As powerVault is free, why not use it for showing a correct and complete CAD BOM in Vault?

With the Data Standard CAD BOM you’ll get two files, the FileBOM.ps1 (addinVault folder) and the CAD BOM.XAML (Configuration/File folder). To make it simple, we will replace the content of such files. For security reasons, it’s better you make a copy before. Best is if you copy the file to a separate folder in order to prevent conflicts with other PS1 files.

Let’s start with the PowerShell script FileBOM.ps1. The new content looks like this:

function GetFileBOM($fileID)
{
  $file = Get-VaultFile -FileId $fileID
  $bom = Get-VaultFileBOM -File $file._FullPath -GetChildrenBy ExactVersion #ExactVersion,LatestVersion,LatestReleasedVersion,LatestReleasedVersionOfRevision
  $dsWindow.FindName("bomList").DataContext = $bom
  return $bom
}

Pretty simple. With Get-VaultFile we get a complete file object. With Get-VaultFileBOM we get the BOM. The interesting thing about the Get-VaultFileBOM is the parameter GetChildrenBy, which allows you to define whether you like to see the BOM as it has been checked in the last time, or see how the BOM could be by using the latest version, latest released version or latest released from current version. More details about these options can be found here.

The XAML file CAD BOM.xaml is also pretty simple

<?xml version="1.0" encoding="utf-8"?>
<UserControl xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" x:Name="MainWindow" xmlns:WPF="clr-namespace:CreateObject.WPF;assembly=CreateObject">

<DataGrid Name="bomList" AutoGenerateColumns="False" IsReadOnly="True" ColumnWidth="Auto" HorizontalGridLinesBrush="WhiteSmoke" VerticalGridLinesBrush="WhiteSmoke">
  <DataGrid.Columns>
    <DataGridTemplateColumn>
      <DataGridTemplateColumn.CellTemplate>
        <DataTemplate>
          <Image Source="{Binding Thumbnail.Image}" Height="35"/>
        </DataTemplate>
      </DataGridTemplateColumn.CellTemplate>
    </DataGridTemplateColumn>
    <DataGridTextColumn Header="Position" Binding="{Binding Bom_PositionNumber}"/>
    <DataGridTextColumn Header="Part Number" Binding="{Binding _PartNumber}"/>
    <DataGridTextColumn Header="Quantity" Binding="{Binding Bom_Quantity}"/>
    <DataGridTextColumn Header="Unit" Binding="{Binding Bom_Unit}"/>
    <DataGridTextColumn Header="Material" Binding="{Binding Bom_Material}"/>
    <DataGridTextColumn Header="Type" Binding="{Binding Bom_Structure}"/>
    <DataGridTextColumn Header="State" Binding="{Binding _State}"/>
    <DataGridTextColumn Header="Revision" Binding="{Binding _Revision}"/>
    <DataGridTextColumn Header="Name" Binding="{Binding _Name}"/>
    <DataGridTextColumn Header="Title" Binding="{Binding _Title}"/>
    <DataGridTextColumn Header="Description" Binding="{Binding _Description}"/>
  </DataGrid.Columns>
</DataGrid>
</UserControl>

You can take the code above and respectively replace the code in the according files. Restart Vault, and enjoy!

I know, you want to sort the BOM. Well, this is a bit tricky, but is doable. The code in the FileBOM.ps1 must be tweaked a bit. There are the rows responsible for sorting

$dsWindow.FindName("bomList").Items.SortDescriptions.Clear()
$sort = New-Object System.ComponentModel.SortDescription("BOM_PositionNumber","Ascending")
$dsWindow.FindName("bomList").Items.SortDescriptions.Add($sort)
$dsWindow.FindName("bomList").Items.Refresh()

As you can see, in the second row you define the property over which you like to sort and the sort direction.

Oops, the BOM is sorted, but the sort order is alphabetical and not numeric. Well, the BOM_PositionNumber is a string, so let’s transform it into a number

$bom | ForEach-Object {
$_.BOM_PositionNumber = [int]$($_.BOM_PositionNumber)
}

Here the complete code:

function GetFileBOM($fileID)
{
  $file = Get-VaultFile -FileId $fileID
  $bom = Get-VaultFileBOM -File $file._FullPath -GetChildrenBy ExactVersion #ExactVersion,LatestVersion,LatestReleasedVersion,LatestReleasedVersionOfRevision
  $bom | ForEach-Object {
    $_.BOM_PositionNumber = [int]$($_.BOM_PositionNumber)
  }
  $dsWindow.FindName("bomList").DataContext = $bom
  $dsWindow.FindName("bomList").Items.SortDescriptions.Clear()
  $sort = New-Object System.ComponentModel.SortDescription("BOM_PositionNumber","Ascending")
  $dsWindow.FindName("bomList").Items.SortDescriptions.Add($sort)
  $dsWindow.FindName("bomList").Items.Refresh()
  return $bom
}

As you can see, we get the BOM, cycle through it and set the Position to be numeric, pass the BOM to the XAML dialog and then sort the property we like. That’s it.

If you want to add additional properties in the grid, just go ahead and change the XAML. If you like to see which other properties are available, set the AutoGenerateColumns to True. All the properties provided by the Get-VaultFileBOM will become visible. You can then pick the one you like, add them to your list and then set the AutoGenerateColumns back to False.

I hope you enjoy your new CAD BOM tab!

This entry was posted in Data Standard, powerVault. Bookmark the permalink.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s