3.3.2.41 Menu

Add, remove, and edit menus, submenus, and menu commands. For more information on menu manipulation, see the menu object.

Notes: You can also do menu manipulation by editing the XML files.


Syntax:

menu  [option] <argumentList [{script}]>

The effects of the menu command may not be immediately apparent. Make a different window type active and then return to the original window to view the result.


Selecting the active menu bar

Menus are different for each Child Window type : Workbook, Graph, Matrix and Layout. To select the active menu bar, use the -g (Graph), -w (Workbook), -p (Layout), or -m (Matrix) command options (see Options below).

Note The window designations can be combined, so that: menu -gp;

makes all subsequent menu modifications apply both to graph and layout page windows.

Selecting the active menu

All subsequent commands operate on the active menu. To select the active menu, do one of the following:

  • Reference the current position in the menu bar (see the "When No Option is Given" section).
  • Use tags. For example:
menu ?Ed; //makes the Edit menu active

Only built-in menus can be referenced this way (for the user-defined menus, reference the position). Tags must have two characters. The following tags are used:

Menu Tag Applicable Window
File Fi w, g, m, p
Edit Ed w, g, m, p
View Vi w, g, m, p
Plot Pl w, m
Graph Gr g
Data Da w, g
Analysis An w, g, m, p
Format Fo w, g, m, p
Layout La p
Matrix Ma m
Image Im w, m
Window Wi w, g, m, p
Statistcs St w
Tools To w, g, m
Column Co w
Help He w, g, m, p


Finding a menu command ID

To find a menu command ID, do one of the following:

  • Press CTRL+SHIFT and select any menu option. The menu ID (and script, if applicable) is typed to the Script window, but not executed. If source code exists for the menu option ( LabTalk or Origin C ) then Code Builder will open with the source file.
  • Use the menu.lastID or the menu.lastExeID object properties

Options:

no option;

Syntax: menu message

When no option is given (i.e. no dash option such as -d), the menu command has four possible actions:

If argumentList consists of only a number:

The menu in the numbered location is set as the active menu. You must set a menu as active before it can be edited. Menus are numbered sequentially, where 1 = File, 2 = Edit, etc. A submenu can also be selected, such that 1.1 is the submenu from the first menu command of the File menu. Example 1:

menu 2;

Sets as active the menu at position number 2 in the active menu bar. Example 2:

menu 1.1;

Sets as active the submenu at position 1 of menu 1 in the active menu bar.

If argumentList is a number followed by a name:

The named menu is created and inserted into the given position in the active menu bar, creating a top-level menu and setting it as the active menu. Example:

menu 2 (My Menu);

Inserts My Menu into position 2 in the active menu bar. The "( )" ensures that My Menu is treated as a single word.

If argumentList does not start with a number:

It is taken to be the name of a new menu command, which is appended to the active menu (in the active menu bar). The new menu command executes the script script. Example:

menu (Add Text) {label -e NewText;}

Adds a new text label to the active window.

If no argumentList is given:

A menu command separator is appended to the active menu (in the active menu bar). Example:

menu 6;
menu;

Appends a menu command separator to menu 6.

This example creates a new Graph menu at position 5 (between Graph and Data menu options) that has two menu options and a separator:

menu -g;
menu 5 (Publish);
menu (To Journal) {type -a Add code here;}
menu;
menu (To Web) {type -a Add code here;}

-cr; Reset all collapsible menus to factory default

Syntax: menu -cr

Minimum Origin Version Required: 2015 SR0

This will reset the Origin collapsible menus back to factory default for both main and context menus.

-d; Delete the menu command at position position in the active menu

Syntax: menu -d position

Delete the menu command at position position in the active menu (in the active menu bar). A separator could be the target position. Menus below a deleted menu move up so a repeated will delete several menus:

menu -w;               // Workbook menu is active
menu ?Co;              // Column menu is active
// Remove last 7 items in menu, including two separators
repeat 7 {menu -d 17;}

menu.cleanup() will restore all menus. See the LabTalk: Language Reference: Alphabetical Listing of Objects: menu object.

-e; Execute the menu command with the specified ID

Syntax: menu -e ID

Execute the menu command with the specified ID by running its script immediately. See the above heading Finding a Menu Command ID.

-g; Select the graph window menu bar for menu manipulation

Syntax: menu -g

Select the graph window menu bar for menu manipulation.

-i; Insert a new menu command called menuName of the active menu bar at position position

Syntax: menu -i position menuName {script}

Insert into the active menu of the active menu bar at position position, a new menu command called menuName. MenuName is associated with the script script. When adding this menu you should only have one menu bar active, as in menu -w;. If multiple menu bars are active, as in menu -wg;, then menus will be added, but the script will not run.

-i; Insert a new menu command menuName with the munu ID ID of the active menu bar at position position

Syntax: menu -i position menuName ID

Insert into the active menu at position position, a new menu command called menuName with the menu ID ID. This command option is used to create a menu command with a specific ID to link to a tool.

-l; Construct a submenu at the end of the active menu

Syntax: menu -l [-i position] (menuName) {script} ]

Construct a submenu at the end of the active menu. The menu -l command must be issued twice, first to name and initialize the submenu, and the second time to construct the submenu that has been described. This protocol is:

menu -l (New Submenu);  
  // begin submenu
menu (submenu 1) {type "this is submenu 1"};
menu (submenu 2) {type "sub menu 2"};
menu -l;  
  // terminate submenu

This script creates a submenu named New Submenu. This submenu contains two menu commands. Submenus can also be constructed at specific positions in the active menu if the -i position option is added between -l and menuName.

Note: When adding menu items to the Window menu, you should insert (using menu -i pos) new items before the window submenu list. Origin will force attempts to create a submenu below position 16 to create the menu at position 16.

-m; Select the matrix window menu bar for menu manipulation

Syntax: menu -m

Select the matrix window menu bar for menu manipulation.

-p; Select the layout page window menu bar for menu manipulation

Syntax: menu -p

Select the layout page window menu bar for menu manipulation.

-q; Execute the menu command with the specified ID by queuing its script

Syntax: menu -q ID

Execute the menu command with the specified ID by queuing its script.See the above heading Finding a Menu Command ID.

-r; Remove the entire menu located at position position

Syntax: menu -r position

Remove the entire menu located at position position. This will remove top-level menus and cannot be used with sub-menu notation like 3.6. You can also refer to the tag as in

menu -r ?He;   // Remove the Help menu from the active menu bar

-w; Select the worksheet menu bar for menu manipulation

Syntax: menu -w

Select the worksheet menu bar for menu manipulation.


-v; Select main menu bar for menu manipulation if no window is active

Syntax: menu -v

Select main menu bar for menu manipulation if no window is active

Examples:

Example 1: Adding Menus and Submenus (without the -l option)

The following script inserts and makes active a NewDD menu at the third position in the active menu bar(s). (If no menu has been set as active, then this command has no effect.)

menu 3 (NewDD);

The next script inserts and makes active a Before Edit menu before the Edit menu in the active menu bar(s).

menu ?Ed (Before Edit);

The next script inserts a SubMenu 'Sample SubMenu' at the fourth position in the second top-level menu and for the active menu bar(s) and makes it the active menu item.

menu 2.4 (Sample SubMenu);

Example 2: Adding Menus and Submenus (with the -l option)

The following script inserts a Before Edit menu before the Edit menu. It then adds a two menu options, each with two submenu commands. These options are available for Workbook and Graph windows.

menu -wg;
menu ?Ed (Before Edit);
menu -l (Sample Option A);
menu (First Command) {type -b First;}
menu (Second Command) {type -b Second;}
menu -l;
menu -l (Sample Option B);
menu (1st Command) {type -a Option B, first command;};
menu (2nd Command) {type -a Option B, second command;};
menu -l;

Example 3: Removing Menus

The following script removes the fourth menu from the active menu bar(s).

menu -r 4;

The next script removes the Format menu from the active menu bar(s).

menu -r ?Fo;

Example 4: Making Menus and Submenus Active:

The following script sets the graph window menu bar active. It then makes the fourth menu from the left active.

menu -g;
menu 4;

The next script makes the View menu active in the active menu bar(s).

menu ?Vi;

Example 5: Adding Menu Commands

Menu commands can only be added to the active menu. Therefore, make the desired menu active before adding menu commands.

The following script appends the menu command labeled EndEdit to the Edit menu in the Workbook, Graph, Matrix and Layout menu bars.

// Use the Workbook, Graph, Matrix 
//and layout Page as the active menu bars
menu -wgmp;   
menu ?Ed;     // Makes Edit the active menu
menu (EndEdit) {type -b "EndEdit";};

The next script inserts the MyItem menu command at the fifth position in the active menu of the active menu bar(s).

menu -i 5 (MyItem) {type -b "My item text.";};

The following script inserts the Open Template menu command in the second position of the Graph menu in the graph menu bar.

menu -g;  
menu 4;  
menu -i 2 (Open Template) {win -t plot line;};

To get a menu ID you must execute the new menu command by selecting it from the menu bar. Then type in the Script window and press Enter button:

MyID = i

You can later execute the menu command by using:

menu -e myId;

Example 6: Removing Menu Commands:

The following script sets the graph window menu bar active. It then sets the sixth menu from the left in the graph window menu bar active, and deletes the second menu command in this menu.

menu -g;
menu 6;
menu -d 2;

Example 7: Adding Menu Command Separators:

The next script adds a menu separator to the end of the Analysis menu of a Workbook. Then a new command is added to the menu.

menu -w;
menu ?An;
menu;
menu (My Analysis) {type -b That was easy.;};