Fixing the BOM blob

With Vault 2017, Autodesk introduced a new job type: autodesk.vault.extractbom.inventor. This job fixes the file BOM blob. The file BOM blob is an object stored in the Vault database on each CAD file record. It is created by the Vault CAD add-in, which saves the CAD BOM information on each check-in into Vault. When you perform an “Assign-Item”, the file BOM blob is used for creating the items and the according bill of material. If the file BOM blob is missing or corrupt, then the assign-item will just create the master item and either no BOM or a wrong BOM.

This is where the new job comes in. You can queue a job for the Inventor files (iam, ipt) with issues, and the job will recreate the file BOM blob object for such files. In order to update the BOM blob object in the Vault database, a new API have been introduced: SetBomByFileId. This API allows to update the file BOM blob, without creating a new version.

To be fair, the BOM blob is usually OK, so you don’t need this job on a day-by-day situation. However, if you imported data/files from a legacy system via BCP and you did not create the BOM blobs, then you will experience that the assign-items will not work, and you have to open the assemblies and components one by one and save them back into Vault in order to fix the problem.

The question now is how to queue this new job. You can use the LifecycleEventEditor and queue the job on lifecycle change, or with Vault 2018 you can set this up on the lifecycle transition settings. I’d like to show you how to queue the job via a VDS context menu or with a stand alone PowerShell script. This would give you the ability to queue the job for a selection of files or the complete list of Inventor files.

Let’s create a custom menu item via Vault Data Standard. We start by adding the menu entry in the MenuDefinitions.xml. Here is the menu item

<cOqueueExtractBomJob Label="Fix BOM" Description="Fix BOM" Hint="Fix BOM" PSFile="queueExtractBomJob.ps1" Image="coolOrange.ico" ToolbarPaintStyle="TextAndGlyph" NavigationTypes="File" MultiSelectEnabled="True" />

And here is how to edit the MenuDefinitions.xml:

The according PowerShell script, which goes to C:\ProgramData\Autodesk\Vault 2017\Extensions\DataStandard\Vault\addinVault\Menus\queueExtractBomJob.ps1 looks like this:

$files=$vaultContext.CurrentSelectionSet
foreach($file in $files)
{
  Add-VaultJob -Name "autodesk.vault.extractbom.inventor" -Description "Fix BOM for '$($file.Label)'" -Priority LOW -Parameters @{"EntityClassId"="File";"FileMasterId"=$file.Id}
}

As you can see, it takes the selection, and for each file it adds a job. Wait, what is Add-VaultJob??? It’s a new command-let that have been introduced in powerVault just few days ago. As the name says, it allows you to queue a job in a super simple way. Just pass the name of the job, the description, the priority and the parameters, and you are done! So, restart Vault, select some Inventor files, and trigger the function. You will see that jobs have been added to the queue.

OK, let’s now create the stand alone script. We will use powerVault again, for queuing a huge amount of jobs. We will perform a search via the Vault API and queue the job. The script looks like this:

Import-Module powerVault
Open-VaultConnection -Server "localhost" -Vault "Vault" -User "Administrator" -Password ""
$srchCond = New-Object Autodesk.Connectivity.Webservices.SrchCond
$srchCond.PropDefId = 33
$srchCond.PropTyp = "SingleProperty"
$srchCond.SrchOper = 1
$srchCond.SrchRule = "Must"
$srchCond.SrchTxt = "ipt"

$bookmark = ""
$srchStatus = New-Object Autodesk.Connectivity.Webservices.SrchStatus
$counter = 0
while($bookmark -eq "" -or $counter -lt $srchStatus.TotalHits)
{
  $files = $vault.DocumentService.FindFilesBySearchConditions(@($srchCond),$null,$null, $true, $true, [ref]$bookmark, [ref]$srchStatus)
  foreach($file in $files)
  {
    $job = Add-VaultJob -Name "autodesk.vault.extractbom.inventor" -Description "Fix BOM for '$($file.Name)'" -Priority LOW -Parameters @{"EntityClassId"="File";"FileMasterId"=$file.MasterId}
    $counter++
  }
}

It imports powerVault and connects to Vault. Adapt the connections information as needed. It then defines a search condition, where the file extension contains ipt. In my case, the PropDefId (which is the internal property definition ID) for File Extension, is 33. In your Vault, this might be different. In order to find the PropDefId, you might use the Vault API or, like I did, perform a search in Vault with your preferred criteria and use vapiTrace for spying the arguments, like here:

Back to the script, we then make a look and search over and over again for the files. The loop is necessary, as the search always returns just 100 records, so we have to cycle through this several times in order to hit all. Within the loop, we queue the job like before.

In the code sample above, we perform the search for IPTs. In order to fix all the BOM issues, you will have to queue the job for IAMs and IPTs. The BOM blob is quite complex, and it relies on the child components, so also the children must have a correct BOM blob.

So, now you can import your files in Vault, maybe via BCP, don’t care about the file BOM blob, and use the Autodesk job for fixing it. Via powerVault this becomes super simple.

 

This entry was posted in Data Standard, PowerShell, powerVault, Vault BCP. 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