Example 1: Create/Add Menus

This script adds a menu, a submenu, and menu items, to the application menu bar and Component popup menus and associates a script function with the selection of the menu item.

You can use this script via any of the methods described in “Running Scripts”.

Note:

Whenever you create a custom menu with a script, be sure to include the following line in the script (This line is necessary to prevent Designer from crashing when the script is executed):

Scripting.DontExit = True

For this script to run and for the created menu to appear, a schematic sheet must be active.

Note:

Xpedition Layout and Xpedition Designer each use different command bar servers. Scripts must call the correct command bar server for the respective product. Use MGCSDD.CommandBarsEx for Xpedition Layout menus; use CommandBarsEx by referring to CommandBars property for Xpedition Designer menus.

Scripting.DontExit = True 
' Insert a new 6th menu in Sheet Menu Bar. When the sheet is opened, the 
' the menu will appear between the existing Add and Format menus. 
Set menu = CommandBars("Sheet Menu Bar").Controls.Add(cmdControlPopup,,,6) 
' Menu text 
menu.Caption = "&Data Sheet" 
' Add a menu item to the menu 
Set button = menu.Controls.Add   
' Menu item text 
button.Caption = "View Data Sheet" 
' Action to perform when the menu item is selected. 
button.OnAction = "run Doc_example2.vbs" 
' Menu item is "grayed" out and cannot be activated; Set to True 
' to enable the menu item's selection. 
button.Enabled = False  
' ********* 
' Add a menu item to the Component Popup menu.  The menu item will 
' open the data sheet for the selected component.  
Set menu = CommandBars("Component Popup").Controls.Add(cmdControlPopup,,,2) 
' Menu text 
menu.Caption = "&Data Sheet" 
' Add a submenu 
Set button = menu.Controls.Add  ' Add a button to the menu 
' Submenu item text 
button.Caption = "View Data Sheet" 
' Action to perform when the submenu item is selected 
button.OnAction = "run doc_example2.vbs" 
'****** 
' Add an entry to an existing toolbar menu, View, to view the data sheet 
' of the selected component.  The Item property is an Indexed property 
' therefore, one must count the menus to identify index.  Be sure to 
' include any "spacers" which may have been added. 
' 
' Modmenu represents the View menu Object. 
Set Modmenu = CommandBars("Sheet Menu Bar").Controls.Item(3)  
' Adding a menu item to the Modmenu Object, the View menu. 
Set AddItem = Modmenu.controls.Add 
' Menu item text 
AddItem.Caption = "View Data Sheet" 
' Action to perform when the menu item is selected 
AddItem.OnAction = "run doc_example2.vbs" 
' 
' *********** 
' Example of deleting a menu item. 
' Create an object which represents the menu, or menu item, 
' to delete. If the menu is within a main menu, you need to 
' "drill down" to that menu item, much the way the add works 
' above. 
Set DelmenuItem = CommandBars("Sheet Menu Bar").Controls.Item(8)  
' "Execute" the Delete method. 
DelMenuItem.Delete