Start a new topic

Assign an item with an CAD-File

Hello at all,


I like to assign an item to a file via powershell. Can someone give me an example of code how to do this.


In other words: I like to to the command "Item update" (see attached Picture) via powershell and not in Vault.


Thanks in advance for helping!




Hello Martin,

Thank you for reaching out to us. Unfortunately there is no cmdlet in powerVault that is equivalent to "Assign / Update Item" in Vault. This is still possible to achieve using the Vault API. Here is an example:

First you can set the assignment behavior. Possible values are None, Existing or All. For reference please have a look at this page on the Autodesk Knowledge Network.

$vault.ItemService.SetItemAssignmentBehavior("None")


Then you need to get the assignment behavior because it needs to be used later:

$AssignmentBehavior = $vault.ItemService.GetItemAssignmentBehavior()


Promote the files you want to assign

$filesToPromote = $vault.ItemService.AddFilesToPromote([file ids], $AssignmentBehavior, [autoassign duplicates $true or $false])


Get a timestamp and promote the files:

$time = Get-Date
$PromoteComponentOrder = $vault.ItemService.GetPromoteComponentOrder([ref]$time)
$PromoteComponents = $vault.ItemService.PromoteComponents($time, $PromoteComponentOrder.PrimaryArray)


Finally create the item

$PromoteComponentsResult = $vault.ItemService.GetPromoteComponentsResults($time)
$UpdateAndCommit = $vault.ItemService.UpdateAndCommitItems($PromoteComponentsResult.ItemRevArray)


For further reference please have a look at this page.


Kind regards,

Manuel Cassan

Hello Manuel,


thank you for your help.

I used the code and it works. But I generate a new Item. In my case I like to assign an existing item. The value of the existing item is stored in the equivalence value. So please can you tell me how to add the file to an existing item?


Thanks a lot for your help!


Kind Regards,

Martin 

Hello Martin,

to update existing items please have a look at the Update-VaultItem cmdlet on the coolOrange Wiki.


Kind regards,

Manuel Cassan

Hello Manuel,


I know this cmdlet. But I can not assign a file to the Item with the Update-VaultItem. I can only add a file. I Need an association.

Do you have a solution for me?


Thanks in advance!

Martin

Hello Martin,

To assign a file to an item you can use following code to get the item using the file Id:

$item = $vault.ItemService.GetItemsByFileId($file.Id)


Then you'll need the item RevId and the Id of the file you want to assign add to add a new file to the item:

$vault.ItemService.AssignFileToItem($item.RevId, $fileToAdd.Id)


Kind regards,

Manuel Cassan

Login or Signup to post a comment