Create Command for the Custom Entity in Vault

By Barbara Han

Vault 2013 introduces a new feature “Custom Entity” (also called “Custom Object” from Vault Explorer UI), and our 3-rd party developers may want to add commands to the context menu on the custom entity. This can be done straightly.

First of all, find the Name of the Custom Entity. This Name is not display name or display plural name as what you see from UI. It is a string like a GUID. You can run a small app to find the Name of the Custom Entity. Please refer to below VB.NET sample code:

Dim custEntSvc As CustomEntityService = ServiceManager.CustomEntityService

Dim defs As CustEntDef() = custEntSvc.GetAllCustomEntityDefinitions()

For Each def As CustEntDef In defs

  If def.DispName = "CustObjTest" Then

    System.Diagnostics.Debug.Print(def.Name)

    Exit For

  End If

Next

Next, you can add the command through a Vault Explorer extension application. The code is very similar like the one that creating the command for file or other entities, but the CommandItem.NavigationTypes needs to change to create a SelectionTypeId for the custom entity and CommandSite.Location needs to point to custom entity’s context menu. Please refer to below VB.NET sample code snippet for more details:

‘ This function tells Vault Explorer what custom commands this extension provides.

‘ Part of the IExtension interface.

‘ A collection of CommandSites, which are collections of custom commands.

Public Function CommandSites() As IEnumerable(Of CommandSite) Implements IExtension.CommandSites

 

  ‘ Create the Hello World command object.

  ‘ This command is active when a custom entity is selected

  ‘ This command is not active if there are multiple entities selected

  Dim helloWorldCmdItem As New CommandItem("HelloWorldCommand", "Hello World…") With { _

.NavigationTypes = New SelectionTypeId() {New SelectionTypeId("45466327-8edd-4ef4-a6df-295d8c1bd2cb")}, _

   .MultiSelectEnabled = False _

  }

  ‘.NavigationTypes = New SelectionTypeId() {SelectionTypeId.File, SelectionTypeId.FileVersion}, _

 

  ‘ The HelloWorldCommandHandler function is called when the custom command is executed.

  AddHandler helloWorldCmdItem.Execute, AddressOf HelloWorldCommandHandler

 

  ‘ Create a command site to hook the command to the Advanced toolbar

  Dim toolbarCmdSite As New CommandSite("HelloWorldCommand.Toolbar", "Hello World Menu") With { _

   .Location = CommandSiteLocation.AdvancedToolbar, _

   .DeployAsPulldownMenu = False _

  }

  toolbarCmdSite.AddCommand(helloWorldCmdItem)

 

  ‘ Create another command site to hook the command to the right-click menu for custom entity.

  Dim fileContextCmdSite As New CommandSite("HelloWorldCommand.FileContextMenu", "Hello World Menu") With { _

   .Location = New CommandSiteLocation("45466327-8edd-4ef4-a6df-295d8c1bd2cb", CommandSiteLocationType.ContextMenu), _

   .DeployAsPulldownMenu = False _

  }

  ‘.Location = CommandSiteLocation.FileContextMenu, _

  fileContextCmdSite.AddCommand(helloWorldCmdItem)

 

  ‘ Now the custom command is available in 2 places.

 

  ‘ Gather the sites in a List.

  Dim sites As New List(Of CommandSite)()

  sites.Add(toolbarCmdSite)

  sites.Add(fileContextCmdSite)

 

  ‘ Return the list of CommandSites.

  Return sites

End Function


Comments

3 responses to “Create Command for the Custom Entity in Vault”

  1. Hi,
    I am looking for some help with a custom object I have created in Vault 2014. I want to add a property instance to my custom object, from the API I am using UpdateCustomEntityProperties() I am passing in a customEntityId which gives me an error BadEntityId when I run this code?
    // Adds a Property Instance to the Custom Entity
    entSvc.UpdateCustomEntityProperties(customEntityId.ToSingleArray(), propDefId.ToSingleArray(), propValue);
    Also I need to pass in a propDefIds does this value need to be a GUID value?
    Hope that you can point me in the right direction?
    Many thanks,
    Barry

  2. Hi,
    I am looking for some help with a custom object I have created in Vault 2014. I want to add a property instance to my custom object, from the API I am using UpdateCustomEntityProperties() I am passing in a customEntityId which gives me an error BadEntityId when I run this code?
    // Adds a Property Instance to the Custom Entity
    entSvc.UpdateCustomEntityProperties(customEntityId.ToSingleArray(), propDefId.ToSingleArray(), propValue);
    Also I need to pass in a propDefIds does this value need to be a GUID value?
    Hope that you can point me in the right direction?
    Many thanks,
    Barry

  3. Hi Barbara, how can I add a button with a icon (image), instead of a text in the advance toolbar menu?
    Thank’s!
    Alain

Leave a Reply

Discover more from Autodesk Developer Blog

Subscribe now to keep reading and get access to the full archive.

Continue reading