Add-InventorMenuItem

Add a menu item to an Inventor menu with an Action that is invoked when the menu item is clicked.

Syntax

Add-InventorMenuItem -Name <String> -Action <Scriptblock | String> [<CommonParameters>]

Parameters

Type

Name

Description

Default Value

Optional

String

Name

Display name of the menu item displayed in the Inventor tab

no

Scriptblock / String

Action

Script block or function name that is executed when the menu item is clicked.

no

Warning: Name must be unique

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

Return type

empty

Remarks

The cmdlet can be used to extend the Inventor user interface with a new menu item which is displayed in a coolOrange Tab.
The coolOrange Tab and its menu items will be displayed in the following Inventor Ribbons:

  • Part

  • Assembly

  • Drawing

  • Presentations

The script block or function name passed to the Action parameter is invoked when the menu item is clicked.
The PowerShell variables provided by Open-VaultConnection and a $inventor variable are available during the execution of the registered action to allow access to the Vault and Inventor APIs.

Menu items created by the cmdlet are not permanent, when Inventor is restarted the menus are reset to their original state.

Calling the cmdlet with the same 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 an Inventor process.

  • The cmdlet is executed only after a successful login to Vault, which can be done via the Inventor Vault Add-in.

Examples

Adds a menu item to add a virtual compontent with an overridden Quantity to the structured BOM:

Add-InventorMenuItem -Name "Add oil to BOM" -Action {
        $compName = 'Oil'
        $document = $inventor.ActiveDocument
        $occur = $document.ComponentDefinition.Occurrences
        try{
            $virtualComponent = $occur.AddVirtual($compName, $inventor.TransientGeometry.CreateMatrix())
        }catch { 
            Write-Host "Could not add virtual component!"
            return
        }
        $BOM = $document.ComponentDefinition.BOM
        
        if (-not $BOM.StructuredViewEnabled) {
            $BOM.StructuredViewEnabled = $True
        }
        $structBomView = $BOM.BOMViews | Where-Object {$_.ViewType -eq [Inventor.BOMViewTypeEnum]::kStructuredBOMViewType } | Select-Object -First 1
        $bomCom = $structBomView.BOMRows | Where-Object {($_.ComponentDefinitions | Select-Object -First 1).DisplayName -eq $compName}
        $bomCom.TotalQuantity = '10'
}

Adds a menu item to create new Vault Change Order with current document attached:

Add-InventorMenuItem -Name "Create changeorder" -Action {
    $docName = $inventor.ActiveDocument.DisplayName
    $file = Get-VaultFile -Properties @{'Name' = $docName}
    if($null -eq $file){
        Write-Host "Could not find vaulted file for current document: '$docName'"
        return
    }
    $coNumScheme = $vault.NumberingService.GetNumberingSchemes('CO', [Autodesk.Connectivity.WebServices.NumSchmType]::ApplicationDefault) | Select-Object -First 1
    $coNumber = $vault.ChangeOrderService.GetChangeOrderNumberBySchemeId($coNumScheme.SchmID)
    $co = Add-VaultChangeOrder -Number $coNumber
    Write-Host "Created ChangeOrder with number '$coNumber'"
    if($null -eq (Update-VaultChangeOrder -Number $co._Number -AddAttachments @($file._FullPath))){
        Write-Host "Attaching file to changeorder failed"
    }
}