Unique part number check


About a year ago, we posted how to pick a Vault item from within Inventor. It’s a simple Data Standard customization that helps designer assigning a Vault item right during the design process and so set the part number appropriately.

Recently we got a question, whether it’s possible to check if the part number is already used on another file – so is it unique within Vault. Obviously this is doable.

For this, we simply subscribed the property changed event of the part number in the Inventor Data Standard dialog. Whenever the part number gets set or changed, the event is triggered.

function InitializeWindow
      #rules applying for Inventor
      $Prop['Part Number'].add_PropertyChanged({
        if($source.PropertyName -eq "Value")

As you can see, in the InitializeWindow we added in the Inventor section the subscription to the property changed event for the part number. On every change of such property, our function PartNumberChanged is triggered.

In such function we perform a search in Vault. We look whether a file with such part number already exists. If yes, then we bring up a message to the user, saying the part number is already taken.

function PartNumberChanged
  $srchCond = New-Object Autodesk.Connectivity.WebServices.SrchCond[] 1
  $srchCond[0] = New-Object Autodesk.Connectivity.WebServices.SrchCond
  $srchCond[0].PropDefId = 88
  $srchCond[0].SrchOper  = 3
  $srchCond[0].SrchTxt = $Prop['Part Number'].Value
  $srchCond[0].PropTyp = "SingleProperty"
  $srchCond[0].SrchRule = "Must"
  $bookmark = ""
  $status = New-Object Autodesk.Connectivity.WebServices.SrchStatus
  $files = $vault.DocumentService.FindFilesBySearchConditions($srchCond,$null,$null, $false, $true, [ref]$bookmark, [ref]$status)
  if($files -ne $null) { [System.Windows.Forms.MessageBox]::Show("Part number already exists!!!!","Wrong part number",[System.Windows.Forms.MessageBoxButtons]::OK,[System.Windows.Forms.MessageBoxIcon]::Error) }

As you can see, we define a search condition where we set the property ID, the search operator, the value we search for, etc. Then we perform the search via FindFilesBySearchConditions. If you wonder how do I know the ID, operator, etc., well I used the vapiTrace to spy the Vault API. I just run a search in Vault with such criteria, this way I saw how Vault is doing it, and then copied the code in my script. On the other hand, the search operator is described in the SDK help, and the property definition ID can be retrieved from another API call. But to keep it simple, and because this code does not change once working, I took the short way.

Now you can give a try. There is just only one remark. If you use the dynamic properties for setting the part number, then the event will be triggered on every character you type. This is because the binding is set in this way. Therefore, the search in Vault is executed on each character, which may slow down the key entry and causes some unnecessary searches. Fortunately the Vault search is quite fast, so you will not experience delay in typing.

Like we did this customization for the part number, we can apply this to any other property you like to check in Vault. And it’s not limited to files. You may look for unique project numbers, or some item properties, or figure out the next free number with given pattern, etc.

I hop this helps!

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

6 Responses to Unique part number check

  1. Thierry says:

    I’m interested in this functionality (checking for unique Part number), so this article seems perfect for me.
    But I’m stuck at first code : where do I have to copy/paste this code to get it work ?
    I guess the “inventor Data Standard” is a function from a CoolOrange product… but which one ?

    strange that you don’t use this opportunity to link to one of your product (and thus, make advertisment ..)

  2. Nash Milenkovic says:

    Can this be done (check vault for duplicate part numbes) with Power Shell and output result in csv file?


  3. Tobias Haase says:

    Hi Marco,
    Great Code! Copy Paste and it works :-)


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