Academic Company Events NI Developer Zone Support Solutions Products & Services Contact NI MyNI

Document Type: Tutorial
NI Supported: Yes
Publish Date: Jul 1, 2008


Feedback


Yes No

Related Links - Developer Zone

Related Links - Products and Services

How to easily customize DIAdem with custom menus

1 ratings | 5.00 out of 5
Print

Overview

Custom menus improve ergonomics and ease of use by organizing and presenting frequently used scripts and functions in a way that makes the most sense to the user.

Custom Menus


Custom Menus allow customization of the DIAdem environment to give single or multiple users easy access to specific functions or script operations.
Custom Menus also allow you to easily control DIAdem and expand its functionality. Menu entries give the user the ability to call functions, run scripts, set properties, etc. Custom menus also improve usability by grouping function families or even scripts based on user characteristics and/or requests.



Create a simple menu



There are several ways to create and edit menus in DIAdem, however this article will mostly concentrate on the usage of commands such as:
MenuItemInsert(), MenuItemAdd() and MenuReset().

Let us start with the some variable declarations and definitions:

Dim DDWindows(4) 'Zero based
Dim Window

DDWindows(0) = "NAVIGATOR"
DDWindows(1) = "VIEW"
DDWindows(2) = "ANALYSIS"
DDWindows(3) = "REPORT"
DDWindows(4) = "SCRIPT"

For the sake of this demo, reset any previous menu customization:

'Restores the default settings
Call MenuReset()

Popup menus are panel specific. Thus, you can create different menu configurations for different pannels. The menu api makes it possible to the developer to create or edit menu items in specific panels. The following code adds the same menu entries to all five DIAdem panels:

For each Window in DDWindows

'This call will populate variables such as MenuItemCount
Call MenuItemCountGet(Window, "M")
'Call MenuItemInsert(WndName, MenuItemPos, MenuItemType, [MenuItemTitle], [MenuItemFct])
'This call creates the main entry in the drop down menu area in DIAdem
Call MenuItemInsert(Window, cstr(MenuItemCount), "Popup", "My Menu")
'These calls will create the drop down menu entries
Call MenuItemInsert(Window, cstr(MenuItemCount)&".1", "MENUITEM", "Clear Portal", "call datadelall(1)")
Call MenuItemInsert(Window, cstr(MenuItemCount)&".2", "SEPARATOR", "", "")
Call MenuItemInsert(Window, cstr(MenuItemCount)&".3", "MENUITEM", "Reset Menu", "call menureset()")

Next

After running the previous lines of code DIAdem should display a new menu entry prior to the Help menu entry like this:


Create a menu that automatically shows all scripts in a directory



Custom menus are mainly used to either perform a single command operation or to start a script.
The following portion of the article will show you how to create a menu based on the content of a particular directory structure on your hard drive.
The following code will add menu entries and link them to all VBS files located in a particular directory as determined by the developer.
Once again let us start with the some variable declarations and definitions:

Dim DDWindows(4) 'Zero based
Dim Window
Dim fso,filecollection,file
Dim folder

DDWindows(0) = "NAVIGATOR"
DDWindows(1) = "VIEW"
DDWindows(2) = "ANALYSIS"
DDWindows(3) = "REPORT"
DDWindows(4) = "SCRIPT"

As in the previous example let's reset any previous menu customization:

'Restores the default settings
Call MenuReset()

Create an instance of a "File System Object" to access file information:

Set fso = CreateObject("Scripting.FileSystemObject")
Set folder = fso.GetFolder(AutoActPath)
Set filecollection = folder.Files

Finally determine the path to the desired directory, loop over all .vbs files and add them to the menu:

For each Window in DDWindows
'This call will populate variables such as MenuItemCount
Call MenuItemCountGet(Window, "M")
'This call creates the main entry in the drop down menu area in DIAdem
Call MenuItemInsert(Window, cstr(MenuItemCount), "Popup", "My Menu")
For Each file In filecollection

If(LCase(fso.GetExtensionName(file.path)) = "vbs")Then
'This adds an element to the end
Call MenuItemAdd(Window,"M."&cstr(MenuItemCount),"MenuItem",file.name,"call scriptstart("""&file.path&""")")

End If
Next
Next

After running the previous lines of code DIAdem should display a new menu entry prior to the Help menu entry like this:

Create a company menu


It is quite common in organizations to share not only data but also applications and best practices. The following lines will explain how to create a pool of scripts accessible from any installed copy of DIAdem in your organization.
First you need to define a specific location in your internal network accessible to all working stations running DIAdem. Than you need to define the scripts that should be shared among the users. The next and final step is to edit the ScriptDefault.VBS in the desired working stations to include a simple call that will start a script intended to create the menu.
To do so please open your ScriptDefault.VBS located under <DIAdem>\AddInfo\ and add the following line:

Call ScriptStart("\\my network path\my_company_menu.vbs")

This will make sure that during its launch sequence DIAdem will allways start that specific script to create the company-wide menus.

Related Links:
Adding customized pull down menus to DIAdem

1 ratings | 5.00 out of 5
Print

Reader Comments | Submit a comment »

 

Legal
This tutorial (this "tutorial") was developed by National Instruments ("NI"). Although technical support of this tutorial may be made available by National Instruments, the content in this tutorial may not be completely tested and verified, and NI does not guarantee its quality in any way or that NI will continue to support this content with each new revision of related products and drivers. THIS TUTORIAL IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND AND SUBJECT TO CERTAIN RESTRICTIONS AS MORE SPECIFICALLY SET FORTH IN NI.COM'S TERMS OF USE (http://ni.com/legal/termsofuse/unitedstates/us/).