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

EA-Matic Menu in Action

Download the complete script: EA-Matic MenuHandling

Step 1: defining the menu

<br />
'EA-Matic<br />
'Tell EA what the menu options should be<br />
function EA_GetMenuItems(MenuLocation, MenuName)<br />
	if MenuName = &quot;&quot; then<br />
		'Menu Header<br />
		EA_GetMenuItems = &quot;-&amp;MyAddinMenu&quot;<br />
	else<br />
		if MenuName = &quot;-&amp;MyAddinMenu&quot; then<br />
			'Menu items<br />
			Dim menuItems(1)<br />
			 menuItems(0) = &quot;TreeViewMenu&quot;<br />
			 menuItems(1) = &quot;DiagramMenu&quot;<br />
			 EA_GetMenuItems = menuItems<br />
		 end if<br />
	end if<br />
end function<br />

Step 2: define the menu state

<br />
'Define the state of the menu options<br />
function EA_GetMenuState(MenuLocation, MenuName, ItemName, IsEnabled, IsChecked)<br />
	if MenuName = &quot;-&amp;MyAddinMenu&quot; then<br />
		Select Case ItemName<br />
			case &quot;TreeViewMenu&quot;<br />
				if MenuLocation = &quot;TreeView&quot; then<br />
					IsEnabled = true<br />
				else<br />
					IsEnabled = false<br />
				end if<br />
			case &quot;DiagramMenu&quot;<br />
				if MenuLocation = &quot;Diagram&quot; then<br />
					IsEnabled = true<br />
				else<br />
					IsEnabled = false<br />
				end if<br />
		end select<br />
	end if<br />
	'to return out parameter values we should return an array with all parameters<br />
	EA_GetMenuState = Array(MenuLocation, MenuName, ItemName, IsEnabled, IsChecked)<br />
end function<br />

Step 3: React to user clicking a menu option

<br />
'react to user clicking a menu option<br />
function EA_MenuClick(MenuLocation, MenuName, ItemName)<br />
	 	if MenuName = &quot;-&amp;MyAddinMenu&quot; then<br />
		Select Case ItemName<br />
			case &quot;TreeViewMenu&quot;<br />
				Dim Package<br />
				Set Package = Repository.GetTreeSelectedPackage()<br />
				MsgBox (&quot;Current Package is: &quot; &amp; Package.Name)<br />
			case &quot;DiagramMenu&quot;<br />
				Dim Diagram<br />
				Set Diagram = Repository.GetCurrentDiagram()<br />
				MsgBox(&quot;Current Diagram is: &quot; &amp; Diagram.Name)<br />
		end select<br />
	end if<br />
end function<br />

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.