Add-VaultMenuItem

Add a Menu Item to a Vault Explorer menu with an Action that is invoked when the menu item is clicked.

Syntax

Add-VaultMenuItem -Location <VaultExplorerMenu> -Name <String> -Action <Scriptblock | String> [<CommonParameters>]

Parameters

Type

Name

Description

Default Value

Optional

VaultExplorerMenu

Location

Vault Explorer Menu to be extended with the Menu Item

no

String

Name

Name of the menu item displayed in the Vault Explorer

no

Scriptblock / String

Action

Script block or function with one parameter ($entities) that is executed when the menu item is clicked.

no

VaultExplorerMenu

Enum values:

Name

Description

FileContextMenu

Context menu (right-click menu) for Files

ItemContextMenu

Context menu (right-click menu) for Items

ChangeOrderContextMenu

Context menu (right-click menu) for Change Orders

ToolsMenu

Tools menu in Vault’s Main Menu toolbar

Warning: Name must be unique

When multiple menu items for the same Location are registered, the Name parameter must be unique for each menu item.

Return type

empty

Remarks

The cmdlet can be used to extend the Vault Explorer’s menus with custom Powershell code.
The script block or function passed as the Action parameter is invoked with an array of powerVault entities as parameter, which contains all selected entities selected in the Vault Client.

Contex menu items
Added menu items are grouped into a sub-menu named “powerJobs Client”.
Depending on the Location of the menu item the objects passed to the -Action can be:

  • FileContextMenu: Only File objects

  • ItemContextMenu: Only Item objects

  • ChangeOrderContextMenu: Only Change Order objects

Tools menu items
Added menu items are appended directly to Vault Explorer’s Tools menu.
Depending on the current selection in the Vault Explorer the object passed to the -Action can be powerVault files, items or change orders.
Only entities selected in the main Vault Explorer window are passed to the -Action. The selection in other windows e.g. in the Search dialog or Edit Item window is ignored.

Menu items created by the cmdlet are not permanent, when the Vault Client is restarted the menus are reset to their original state.
The Menu items cannot be removed nor can the name be updated once they have been added.

Calling the cmdlet with the same Location and Name parameter after a menu item has already been added, will update the action for the menu item.

Note

The cmdlet can only be used when running directly in a Vault Explorer Process

Examples

The following samples are meant to be saved as .ps1 files in the powerEvents event scripts folder.

Adds a menu item to the File context menu to queue a DWF job if the file type is supported:

function SubmitDWFJob($entities){
    foreach($file in $entities){
        if($file._Extension -in @('iam', 'ipt', 'ipn', 'idw', 'dwg', 'dxf', 'rvt', 'rfa', 'rte', 'nwd', 'nwf', 'nwc', 'ifc')){
            Add-VaultJob -Name "Autodesk.Vault.DWF.Create.$($file._Extension)" -Parameters @{'FileVersionId' = $file.Id} -Priority 10
        }else{
            [System.Windows.Forms.MessageBox]::Show("File extension '$($file._Extension)' is not supported!")
        }
    }
}
Add-VaultMenuItem -Location FileContextMenu -Name 'Queue DWF job' -Action 'SubmitDWFJob'

Adds a menu item to the Item context menu to queue the powerPLM (powerFLC)Sample.TransferItemBOMs’ job:

Add-VaultMenuItem -Location ItemContextMenu -Name "Transfer Item BOM to FLC" -Action {
    param($entities)
    foreach($item in $entities){
        Add-VaultJob -Name "Sample.TransferItemBOMs" -Parameters @{"EntityId"=$item.Id;"EntityClassId"="Item"} -Description "Transfer Item BOMs for: $($item._Number)"
    }
}

Adds tools menu item to open powerEvents log directory with Windows Explorer:

Add-VaultMenuItem -Location ToolsMenu -Name "Open Log directory" -Action {
	explorer.exe "$env:LOCALAPPDATA\coolOrange\powerEvents\Logs" 
}