Adding Custom Menus and Tool Items in
Allegro System Capture
Introduction
For quicker access to frequently-used commands or custom functionality, you can add extra
menus or toolbar options to Allegro System Capture. The menu and toolbar framework can be
customized with Tcl APIs.
Menus and Actions
To customize the default menu bar, you can add custom menus that contain menu items, actions,
or a combination of both. In the context of menus, Actions are elements that call a Tcl procedure,
whereas pop-up menus group actions and other menus as illustrated in the following screenshot:
Tcl Scripting APIs for Customizing Menus
This section contains API samples for the following tasks:
• Adding menus to the menu bar
• Deleting a menu from the menu bar
• Creating a pop-up menu
• Customizing context menus
• Adding an action to a menu
• Adding menus to the menu bar at a specific position
• Delete an action from a menu
• Adding and deleting separator from menu
• Sample Tcl script to create custom menus
Adding Menus to Menu Bar
To add a custom menu to the menu bar, use the following Tcl API:
addMenuToMenuBar <top-level menu name> <path to icon file> <enabled> <top-level menu name before
which the menu is to be inserted> <context>
In the following example, a menu with the label Custom Menu is added between the Tools and
Help menus in Allegro System Capture.
set customMenu {Custom Menu}
set beforeMenu "Help"
set context "sch"
# add menu to menu bar
addMenuToMenuBar $customMenu {} 1 $beforeMenu $context
Deleting a Menu from Menu Bar
To delete a menu option from the menu bar, use the following Tcl API:
deleteMenuFromMenuBar <Name of Menu to be deleted> <context>
In the following example, the Tool menu is deleted from the menu bar.
deleteMenuFromMenuBar {Tools} {sch}
Creating a Pop-Up Menu
Pop-up menus can be created either under a top-level menu or within other menus. To create a
pop-up menu, use the following Tcl API:
addMenuToMenuName <parent menu name> <pop-up menu name> <path to icon file> <enabled>
In the following example, a pop-up menu called Pop-Up, is added under the main menu, Custom
Menu. Typically, icons are not specified for top-level menus and pop-up menus. This is done by
leaving the icon file path blank.
set customMenu {Custom Menu}
set popupMenu {Pop-Up}
addMenuToMenuName $customMenu $popupMenu {} 1
Customizing Context Menus
Context menus of different object types, such as wires, can be customized using Context Menu Tcl
APIs. This section lists the customizations that can be done to context menus.
• Adding and deleting submenus from a context menu
addMenuToContextMenuEx <contextmenu type> <sub menu name> <menu id>
To add a submenu to a root context menu, use the following:
set wireContextMenuType [getContextMenuType "sch" {Wire} 0]
set contextMenu1Id [createMenuItem ContextMenu1 ContextMenu1 {} 1 1]
# passing empty value in parent field adds the menu to root menu item
addMenuToContextMenuEx $wireContextMenuType {} $contextMenu1Id
• To add a submenu to a context menu submenu, use the following:
set wireContextMenuType [getContextMenuType "sch" {Wire} 0]
set contextMenu1Id [createMenuItem ContextMenu1 ContextMenu1 {} 1 1]
set contextMenu2Id [createMenuItem ContextMenu2 ContextMenu2 {} 1 1]
addMenuToContextMenuEx $wireContextMenuType {} $contextMenu1Id
# add Contextmenu2 to ContextMenu1
addMenuToContextMenuEx $wireContextMenuType ContextMenu1 $contextMenu2Id
• To delete a submenu from a context menu submenu, use the following:
set wireContextMenuType [getContextMenuType "sch" {Wire} 0]
set contextMenu1Id [createMenuItem ContextMenu1 ContextMenu1 {} 1 1]
set contextMenu2Id [createMenuItem ContextMenu2 ContextMenu2 {} 1 1]
addMenuToContextMenuEx $wireContextMenuType {} $contextMenu1Id
# add Contextmenu2 to ContextMenu1
addMenuToContextMenuEx $wireContextMenuType ContextMenu1 $contextMenu2Id
# delete Menu
deleteMenuFromContextMenu $wireContextMenuType ContextMenu2 ContextMenu1
#delete ContrextMenu1 passing null parent removes the menu from root menu item
deleteMenuFromContextMenu $wireContextMenuType ContextMenu1 {}
• Add and delete separators from a context menu
addSeparatorToContextMenu <context menu type> <before menu item> <name of menu to which
separator should be added>
deleteSeparatorFromContextMenu <context menu type> <before menu item> <name of menu from
which separator should be deleted>
• To add and delete a separator from context menu, use the following:
set wireContextMenuType [getContextMenuType "sch" {Wire} 0]
set contextMenu1Id [createMenuItem ContextMenu1 ContextMenu1 {} 1 1]
#passing empty value in parent field adds the menu to root menu item
addMenuToContextMenuEx $wireContextMenuType {} $contextMenu1Id
addActionToContextMenuEx $wireContextMenuType TestAct sampleHandler1 {} {} {} TestAct {} \
sch ContextMenu1
addSeparatorToContextMenu $wireContextMenuType TestAct ContextMenu1
deleteSeparatorFromContextMenu $wireContextMenuType TestAct ContextMenu1
• Add and delete actions from a context menu
addActionToContextMenu <context menu type> <display label> <action command> <path to icon
file> <path to selected icon file> <path to hover icon file> <tool tip> <action shortcut>
<context> <name of sub menu to which action should be added>
deleteActionFromContextMenu <context menu type> <action name> <name of menu from which
action should be removed>
• To add and delete actions from a context menu, use the following:
set wireContextMenuType [getContextMenuType "sch" {Wire} 0]
set contextMenu1Id [createMenuItem ContextMenu1 ContextMenu1 {} 1 1]
#passing empty value in parent field adds the menu to root menu item
addMenuToContextMenuEx $wireContextMenuType {} $contextMenu1Id
addActionToContextMenuEx $wireContextMenuType TestAct {puts "handler1"} {} {} {} TestAct \
{} sch ContextMenu1
#delete action
deleteActionFromContextMenu $wireContextMenuType TestAct ContextMenu1
Adding an Action to a Menu
To add a custom action to a menu, use the following Tcl API:
# add actions to pop-up menus
addActionToMenu <parent menu name> <action label> <tcl procedure name> <path to icon file>
<tooltip> <shortcut key sequence> <context name>
In the following snippet, an action is added to the pop-up menu created in the previous section.
Clicking this menu item displays the string "In custom action" in the Command window.
# define a new Tcl procedure
"customAction" proc customAction {} {
puts "In custom action"
}
# set the pop-up menu name
set popupMenu {Pop-Up}
# set the action name
set customAction {Custom Action}
# set the icon for the action if you have
# an icon file customIcon.png
set iconFile [file normalize customIcon.png]
# add the action to the pop-up menu with the tooltip
# "Custom action in pop-up menu" having an icon
# customIcon.png
addActionToMenu $popupMenu $customAction ::customAction \
$::iconFile {Custom action in pop-up menu} {} {sch}
Adding Menus to the Menu Bar At Specific Positions
Custom menus can be added to the main menu bar before a specific menu using the following Tcl
API, if <name of the menu above which the new menu will be created> is not specified the new
menu gets added at the end of parent menu.
addActionToMenu <parent menu name> <action label> <tcl procedure name> <path to icon file>
<tooltip> <shortcut key sequence> <context name> <name of the menu above which the new menu will be
created>
In the following example, a Custom Menu 5 menu is added above the Documentation option in the
Help menu. Clicking this menu item will display the string "In custom action 5" in the Command
window.
# define a new Tcl procedure
"customAction" proc customAction5 {} {
puts "In custom action 5"
}
# set the action name
set customAction {Custom Action 5}
# set the parent menu name
set parentMenu {Help}
# set the child menu above which the Custom Action 5 menu will be created
set beforeMenu {Documentation}
# set the icon for the action if you have
# an icon file customIcon.png
set iconFile [file normalize customIcon.png]
# add the action to the Help menu above its sub-menu Documentation with the tooltip
# "Custom action in pop-up menu" having an icon
# customIcon.png
addActionToMenu $parentMenu $customAction ::customAction5 \
$::iconFile {Custom action 5} {} {sch} $beforeMenu
Deleting an Action from the Menu
To delete an action from the menu, use the following API:
# add actions to pop-up menus
deleteActionFromMenu <parent menu name from which actions should be removed> <action name>
<context>
The following snippet deletes the Part Developer action from the Tools menu:
# add actions to pop-up menus
deleteActionFromMenu {Tools} {Part Developer} {sch}
Adding and Deleting Separators from Menus
To add a separator to menu, use the following:
# add actions to pop-up menus
addSeparatorToMenu <menu name> <before menu Item>
The following snippet adds a separator before the Part Developer action in the Tools menu:
# add actions to pop-up menus
addSeparatorToMenu {Tools} {Part Developer}
The following Tcl API deletes a separator from the menu:
# add actions to pop-up menus
deleteSeparatorFromMenu <Menu Name> <Before Menu Item>
The following snippet deletes a separator before the Part Developer menu item in the Tools menu:
# add actions to pop-up menus
deleteSeparatorFromMenu {Tools} {Part Developer}
Sample Tcl Script to Create Custom Menus
This script is available at the following location:
<CADENCE INSTALLATION>/share/cdssetup/canvas/samples.
Place this script and the customMenus folder along with the relevant icon file at
$CDS_SITE/cdssetup/canvas/resources/syscap or at
$HOME/cdssetup/canvas/resource/syscap to load the Tcl script when System Capture starts.
A custom menu gets added as shown in the following screenshot:
# ----------------------------------------------------------------------------
# Filename: customMenus.tcl
# This file should be placed in one of the following locations:
# 1. For site-wide availability place it at -
# $CDS_SITE/cdssetup/canvas/resources/syscap/
# 2. For user-only availability place it at -
# $HOME/cdssetup/canvas/resources/syscap/
# ----------------------------------------------------------------------------
# Description: Menu customization through Tcl scripting
# ----------------------------------------------------------------------------
namespace eval customMenus {
variable customIcon [file normalize \
[file join [file dirname [info script]] customMenus customIcon.png]]
}
#############################################################################
# Namespace : customMenus #
# Procedure Name : action1 #
# Description : Custom action for menu sample #
#############################################################################
proc customMenus::action1 {} {
puts "In action 1"
}
#############################################################################
# Namespace : customMenus #
# Procedure Name : action2 #
# Description : Custom action for menu sample #
#############################################################################
proc customMenus::action2 {} {
puts "In action 2"
}
#############################################################################
# Namespace : customMenus #
# Procedure Name : action3 #
# Description : Custom action for menu sample #
#############################################################################
proc customMenus::action3 {} {
puts "In action 3"
}
#############################################################################
# Namespace : customMenus #
# Procedure Name : action4 #
# Description : Custom action for menu sample #
#############################################################################
proc customMenus::action4 {} {
puts "In action 4"
}
#############################################################################
# Namespace : customMenus #
# Procedure Name : action5 #
# Description : Custom action for menu sample #
#############################################################################
proc customMenus::action5 {} {
puts "In action 5"
}
# Menu Structure that will be created
# <.. Other menus ..> Custom Menu Help
# -> Pop-Up
# -> Custom Action 1
# -> Custom Action 2
# -> Custom Action 3
# -> Custom Action 5
# -> Custom Action 4
#
#############################################################################
# Namespace : customMenus #
# Procedure Name : entry #
# Description : Creates menu structure and adds it to the menu bar #
#############################################################################
proc customMenus::entry {} {
# add top-level menu titled "Custom Menu" to the menu-bar
# before the "Help" menu
set customMenu {Custom Menu}
set beforeMenu "Help"
set context "sch"
addMenuToMenuBar $customMenu {} 1 $beforeMenu $context
# create a pop-up menu titled
# "Pop-Up" and add it to the "Custom Menu"
set popupMenu {Pop-Up}
addMenuToMenuName $customMenu $popupMenu {} 1
# Add three actions to the "Pop-Up" menu
# Add custom action 1 to "Pop-Up" menu
set customAction1 {Custom Action 1}
addActionToMenu $popupMenu $customAction1 ::customMenus::action1 \
$::customMenus::customIcon {Custom Menu - Action 1} {} {sch}
# Add custom action 2 to "Pop-Up" menu
set customAction2 {Custom Action 2}
addActionToMenu $popupMenu $customAction2 ::customMenus::action2 \
$::customMenus::customIcon {Custom Menu - Action 2} {} {sch}
# Enable action2 in read-only mode
set actionId2 [getActionId $context $customAction2]
setActionEnabledInReadOnlyState $context $actionId2
# Add custom action 3 to "Pop-Up" menu
set customAction3 {Custom Action 3}
addActionToMenu $popupMenu $customAction3 ::customMenus::action3 \
$::customMenus::customIcon {Custom Menu - Action 3} {} {sch}
# Add a single action directly to the top-level "Custom Menu"
set customAction4 {Custom Action 4}
addActionToMenu $customMenu $customAction4 ::customMenus::action4 \
$::customMenus::customIcon {Custom Menu - Action 4} {} {sch}
# Enable action4 in read-only mode
set actionId4 [getActionId $context $customAction4]
setActionEnabledInReadOnlyState $context $actionId4
# Enable action4 in non-electric mode
set actionNonElectricMode [getActionId $context $customAction4]
setActionEnabledInNonElectricMode $context $actionNonElectricMode
# Add a single action just above sub-menu "Custom Action 4" of top-level "Custom Menu"
set customAction5 {Custom Action 5}
addActionToMenu $customMenu $customAction5 ::customMenus::action5 \
$::customMenus::customIcon {Custom Menu - Action 5} {} {sch} {Custom Action 4}
}
# Install the custom menus and actions
customMenus::entry
Customizing Toolbar Buttons and Actions
Just as the menu bar, the main toolbar in System Capture can also be customized by adding
buttons or icons using Tcl scripting. Custom tool buttons perform an action. Action items are
elements that call a Tcl procedure, or any predefined action. System Capture does not have any
default toolbar buttons.
Allegro System Capture toolbar has three different sections to add custom buttons, the left,
middle, and right sections.
In the following example, these custom items will be added:
• Note to the left section
• Draw Wire to the middle section
• Print to the right section
Tcl Scripting APIs for Customizing the Toolbar
This section contains API samples for the following tasks:
• Adding a button to the toolbar
• Adding a button to the toolbar at a specific position
• Adding separators to the toolbar
• Deleting a separator from the toolbar
• Assigning section numbers to toolbar sections
• Adding actions to Buttons
• Deleting an Actions assigned to a button
• Creating and adding action to a button on the toolbar
• Sample script to create and add buttons to the toolbar
Adding a Button to the Toolbar
To add buttons to the toolbar, use the following Tcl API:
addToolIItemToToolBar <tool item name> <section to which the item is to be added> <action name>
In the following example, the Redo button is added to the left section in the toolbar.
Adding a Button to the Toolbar at a Specific Position
To add buttons to the toolbar at a specific position in the left, middle, or right sections, use the
following Tcl API:
addToolItemToToolBarEx <tool item name> <section to which the item is to be added> <action name>
<position to which the item is to be added in any section>
In the following example, a Copy button is added at the first position, that is to the left of the
previously added Redo button in the left section of the toolbar.
Adding Separators to the Toolbar
To add a separator to the toolbar, use the following API:
addSeparatorToToolBar <context> <section number>
In the following example, a separator is added after previously added Redo button in the left
section of toolbar:
Deleting Separators from the Toolbar
To delete a separator from the toolbar, use the following Tcl API:
deleteSeparatorFromToolBar <context> <section> <after menu item>
The following snippet deletes the separator after the Redo button.
deleteSeparatorFromToolBar {sch} 1 {Redo}
Adding Separator to Toolbar Sections
The following code assigns a unique identifier to each section of the toolbar:
#Adding separator to the toolbar.
#Function takes two arguments first is “context” and other is the position of
the separator.
#0 for left section.
#1 for middle section.
#2 for right section.
#Here we are adding separator to the left section.
set res [addSeparatorToToolBar sch 0]
Adding Actions to Buttons
To add a custom action to a button, first create the action, and then add it to the button.
# Create Action Item
createAction <display label> <command to be executed (tcl procedure name)> <path to the icon file>
<path to the selected icon file> <path to hover icon file> <tooltip> <shortcut key sequence>
Deleting a Toolbar Button
To delete a button from the toolbar, use the following Tcl API:
# Delete Tool Item
deleteToolItemFromToolBar <Tool Item Name> <Section> <Context>
The following snippet deletes the Redo button from the left section of the toolbar:
# Delete Tool Item
deleteToolItemFromToolBar {Redo} 0 {sch}
Creating and Adding Action to a Button on the Toolbar
#This will create an action helloWorld which will print Hello World on the tcl window of System
Capture
createAction helloWorld { puts "Hello World" } {} {} {} {} {}
#This will add the action item helloWorld to the tool button.
addToolItemToToolBar helloWorld 0 "helloWorld"
#This will add the action item Undo to the left section of toolbar at first position,
#index 0 means 1st position
addToolItemToToolBarEx redoButton 0 "Undo" 0
Sample script to create and add buttons to the Toolbar
A sample Tcl script in available to add buttons to the toolbar. This script can be found at:
<CADENCE INSTALLATION>/share/cdssetup/canvas/samples
Place this script and the customToolbar folder along with the relevant icon file at
$CDS_SITE/cdssetup/canvas/resources/syscap or at
$HOME/cdssetup/canvas/resource/syscap, to load the Tcl script when System Capture starts.
The script adds a separator after the Add a Component button in the left section and the Save
Project button after the separator. Another button, Undo, is added to the middle section of the
toolbar.
A helloWorld button with an icon is added to left section of the toolbar along with Undo, Redo, and
Cut buttons in left section. Buttons for Draw Wire, Draw Bus, and Add Note are added to the
middle section. Finally, Print and Create Variant buttons are added to the right section of the
toolbar.
# ----------------------------------------------------------------------------
# Filename: customTool.tcl
# This file should be placed in one of the following locations:
# 1. For site-wide availability place it at -
# $CDS_SITE/cdssetup/canvas/resources/syscap/
# 2. For user-only availability place it at -
# $HOME/cdssetup/canvas/resources/syscap/
# ----------------------------------------------------------------------------
# Description: ToolBar customization through Tcl scripting
# ----------------------------------------------------------------------------
namespace eval customTool {
variable customIcon [file normalize \
[file join [file dirname [info script]] customToolbar customIcon.png]]
}
#############################################################################
# Namespace : customTool #
# Procedure Name : entry #
# Description : Adds tool items to the ToolBar #
#############################################################################
proc customTool::entry {} {
#If ActionName is not present, add createAction command.
#This will create an action helloWorld which will print Hello World on the
#Tcl window of System Capture.
set act [createAction helloWorld {puts "Hello World"} \
$::customMenus::customIcon {} {} {} {}]
#Adding Save Project Button after the separator.
set sepResult [addToolItemToToolBar helloWorldButton 0 "helloWorld"]
#Adding Undo Button to the left section of toolbar.
set sepResult [addToolItemToToolBar undoButton 0 "Undo"]
#Adding Draw Wire Button to the middle section of toolbar.
set sepResult [addToolItemToToolBar wireButton 1 "Draw Wire"]
#Adding Draw Bus Button to the middle section of toolbar.
set sepResult [addToolItemToToolBar busButton 1 "Draw Bus"]
#Adding Print Button to the right section of toolbar.
set sepResult [addToolItemToToolBar printButton 2 "Print"]
#Adding separator to the left tool section of the ToolBar.
set sepResult [addSeparatorToToolBar {sch} 0]
#Adding Copy Button to the left section of toolbar at second position
#index 1 means 2nd position
set sepResult [addToolItemToToolBarEx copyButton 0 "Copy" 1]
}
# Install tool items to the ToolBar.
customTool::entry
The following image shows the toolbar with custom buttons.