Menu item with Data Standard

blog-20141117

In preparation for my Autodesk University (Las Vegas) session with the topic “Introduction to Data Standard”, I’m creating samples around numbering, advanced dialogs in CAD and Vault, some cool tabs for Vault and also menu items. In the next weeks I will post the samples on this blog. However you are welcome to visit my session at AU and pass by to say hello!

Today, I’m going to talk about menu items. Data Standard offers an easy way to create additional menu items and place your personal custom logic behind. In order to demonstrate how this works, I will create a simple menu item that queues a job in the job queue. Actually, the item on the file context menu will place a PDF job in the job queue for the selected files. It’s pretty simple but it explains the technique behind and for all those of you who love powerJobs – our solution for creating PDF files and more – it’s a good and simple add-on.

In order to create a menu item, we need to do two things:

  • editing the mymenu.mnu
  • creating a little PowerShell script file

The mymenu.mnu is located in the DataStandard\Vault folder and contains all the menu item definitions. It’s a simple text file, so you can edit it with any convenient text editor. At the top of the file you will find text blocks or sections that all start with “item” and then the name of the section. An “item” represents a menu item. So, let’s create a new item for the PDF job queuing:

item newPDFJob
{
  Description = "Create PDF";
  Id = "cOCreatePDF";
  Hint = "Create PDF";
  Label = "Create PDF";
  MultiSelectEnabled = true;
  NavigationTypes = [File];
  ToolbarPaintStyle = TextAndGlyph;
  PSFile = "cOCreatePDF.ps1";
  Image="coolOrange.ico";
}

The most attributes of this section are probably self-explanatory. There are just a few things to take attention. The name of the item section must be unique and so must the Id attribute. Inside the mymenu.mnu file you will find a short description of the attributes at the top. The attribute, that we are interested in, is the PSFile, which points to a PowerShell script file. This file is located in the DataStandard\Vault\addinVault\Menus folders. Before we look to the PowerShell file, we have to define where our new menu item shall be displayed on the Vault UI. If you scroll down the mymenu.mnu, you will find further sections called “site” which describe the Vault toolbars and menu. As we like to add our menu item to the context of a file, the section we are looking for is called fileContext. It already exists, so just scroll down and look for it.

site fileContext
{
  Id="DSSiteFileContext";
  Label="myMenu";
  DeployAsPulldown=false;
  Location=FileContextMenu;
  MenuItems=[$newFile, $editFile,$newPDFJob]; } 

The attribute MenuItems contains the list of menu items that shall be displayed in the context menu. So, in our case the $NewJobPDF. Once you save the file and restart Vault, you should see your menu item like this:

menuItem

Let’s have a look to the cOCreatePDF.ps1 file. It does not exist yet, so let’s create one. And this is the content:

foreach ($selection in $vaultContext.CurrentSelectionSet)
{
  $file = $vault.DocumentService.GetLatestFileByMasterId($selection.Id)
  $jobParams = New-Object Autodesk.Connectivity.WebServices.JobParam[] 3
  $jobParams[0] = New-Object Autodesk.Connectivity.WebServices.JobParam
  $jobParams[0].Name = "FileId"
  $jobParams[0].Val = $file.Id
  $jobParams[1] = New-Object Autodesk.Connectivity.WebServices.JobParam
  $jobParams[1].Name = "EntityId"
  $jobParams[1].Val = $file.Id
  $jobParams[2] = New-Object Autodesk.Connectivity.WebServices.JobParam
  $jobParams[2].Name = "EntityClassId"
  $jobParams[2].Val = "File"
  $text = "Create PDF for '"+$selection.Label+"'"
 $vault.JobService.AddJob("coolOrange.powerJobs.CreatePdfAsAttachment",$text,$jobParams,10) } 

The function iterates through the selected elements and for each element it adds a job into the job queue. For our job, we only pass the FileId as a parameter. So, the first couple of lines define the job parameter, while the last line adds the job to the queue with according arguments.

After next start of Vault, we will have a new menu item on the context of a file, which queues a powerJobs PDF creation for the selected files. Of course the logic of the menu item can be enhanced, so that the job gets queued only for certain file types or with some more parameters. However, that’s it. With just a few entries in the mymenu.mnu and an according PowerShell script, we have what we want.

I hope you have an idea how to create new menu items in Vault via Data Standard, an by the way, it’s worth having a look to the other menu items delivered with the standard, such as file and folder creation or edit and the like.

This entry was posted in Data Standard, powerJobs, PowerShell, Vault API and tagged , , , . Bookmark the permalink.

3 Responses to Menu item with Data Standard

  1. Brandon says:

    Has anybody actually gotten this to work? I must be missing something somewhere. Im getting a 1013 error… i think that means file id is invalid? perhaps no file id is getting passed to the createpdf job?

  2. Franz Kefer says:

    Replace $selection.Id with $selection.MasterId
    This should works!

Leave a comment