Example Code

DIAdem Custom Menus from an XML Files

Code and Documents

Attachment

Download All

Introduction

DIAdem offers high levels of customisation through VBS scripts. You can just run these from file but sometimes you want to integrate these into the environment, either because you use them a lot or you want colleagues who aren't as script savvy. This example demonstrates the API for doing this and also using an XML file to define these to create a scalable script for this.

Menu Interface

DIAdem allows you to edit the menus through the MenuItem functions. The key fuction is MenuItemInsert. This allows you to enter one of three items in a particular location. This can either be:

  • POPUP: This creates a menu item which has others below it so you can organise your menu.
  • SEPARATOR: This adds a horizontal bar to the menu.
  • MENUITEM: This is set with a script line to perform an action, normally this is just ScriptStart kicking off the desired script.

The location is then defined with an index value, with a . separating each layer e.g. 1.1 is the normal location for File>>New

Normally you will want the script that runs this to be your start up script so that it is populated on starting DIAdem.

XML

As you add multiple sets of scripts your startup script to add these to the menu can become a mess! Loading a configuration from file is a scalable of keeping a simple script but easy reconfiguration.

XML was chosen for this example as it is a heirarchy based file structure which maps nicely to the menu setup. It is also easy to manipulate programmatically or by hand.

To deal with this file format we use the Microsoft XML parser. This is made available through ActiveX which we can access through the CreateObject function:

Set xDoc = CreateObject("MSXML2.DOMDocument.3.0")

Then we can load the structure, one layer at a time as a collection of the different nodes and each node is an object. The best place for documentation of this tends to be on MSDN.

For this script the XML file contains several different tags.

  • <Menus> : Top level tag of the XML file, the parser seemed to have issues without this.
  • <Window> : This contains a menu for a specific window of DIAdem. It contains the menu structure and has an attribute of name which is the name of the window that the MenuItemInsert function uses e.g. SCRIPT or VIEW
  • <Folder> : This can contain more menu structures and creates a POPUP in the menu. The name attribute is the name.
  • <Separator> : Adds a horizontal line to the menu. Contains nothing and needs no attributes.
  • <Script> : This adds a menu item. It has an attribute name and contains the script it will run.

Attached is an example file which uses msgbox instead of script start to allow you to try it out. Put this and the script in the same folder and run the script. You will then see the menu items added to DIAdem. For more information on MenuItemInsert and similar functions see the DIAdem help or this is covered in the DIAdem Advanced course.

James Mc
========
CLA and cRIO Fanatic
My writings on LabVIEW Development are at devs.wiresmithtech.com

Example code from the Example Code Exchange in the NI Community is licensed with the MIT license.

Contributors