Using the add-in menu with EA-Matic
With EA-Matic you can develop add-ins for Enterprise Architect using the built-in scripting feature of EA.
This example shows how to use the add-in menu to add your own menu and menu option, and react to the user clicking such a menu option.
With this script you can use menu options as a regular add-in would
Download the complete script: EA-Matic MenuHandling
Step 1: defining the menu
'EA-Matic 'Tell EA what the menu options should be function EA_GetMenuItems(MenuLocation, MenuName) if MenuName = "" then 'Menu Header EA_GetMenuItems = "-&MyAddinMenu" else if MenuName = "-&MyAddinMenu" then 'Menu items Dim menuItems(1) menuItems(0) = "TreeViewMenu" menuItems(1) = "DiagramMenu" EA_GetMenuItems = menuItems end if end if end function
Step 2: define the menu state
'Define the state of the menu options function EA_GetMenuState(MenuLocation, MenuName, ItemName, IsEnabled, IsChecked) if MenuName = "-&MyAddinMenu" then Select Case ItemName case "TreeViewMenu" if MenuLocation = "TreeView" then IsEnabled = true else IsEnabled = false end if case "DiagramMenu" if MenuLocation = "Diagram" then IsEnabled = true else IsEnabled = false end if end select end if 'to return out parameter values we should return an array with all parameters EA_GetMenuState = Array(MenuLocation, MenuName, ItemName, IsEnabled, IsChecked) end function
Step 3: React to user clicking a menu option
'react to user clicking a menu option function EA_MenuClick(MenuLocation, MenuName, ItemName) if MenuName = "-&MyAddinMenu" then Select Case ItemName case "TreeViewMenu" Dim Package Set Package = Repository.GetTreeSelectedPackage() MsgBox ("Current Package is: " & Package.Name) case "DiagramMenu" Dim Diagram Set Diagram = Repository.GetCurrentDiagram() MsgBox("Current Diagram is: " & Diagram.Name) end select end if end function
Leave a Reply
Want to join the discussion?Feel free to contribute!