Using a script you can insert one or more items to the Utilities menu. To do this, the [DeclareMenu] attribute is used to call up the MenuFunction() function. If the script is then loaded, the menu item specified by the AddMenuItem function is generated.
The overall structure of such a simple C# script thus looks like this:
public class <ScriptName> { [DeclareMenu] public void MenuFunction() { Eplan.EplApi.Gui.Menu oMenu = new Eplan.EplApi.Gui.Menu(); oMenu.AddMenuItem("<MenuText>","<ActionName>"); } }
A menu item is always linked with an action that is called up when the menu item is selected. This means that either the script has another action (via [DeclareAction]) or that the menu item is already assigned to an existing action.
The following example shows a script in C# that connects an action and a menu item:
public class RegisterScriptMenu { [DeclareAction("MyScriptActionWithMenu")] public void MyFunctionAsAction() { MessageBox.Show("MyFunctionAsAction was called!", "RegisterScriptMenu"); return; } [DeclareMenu] public void MenuFunction() { Eplan.EplApi.Gui.Menu oMenu = new Eplan.EplApi.Gui.Menu(); oMenu.AddMenuItem("MyMenuText", "MyScriptActionWithMenu"); } }
In the example above, the AddMenuItem() function generates the menu item MyMenuText from the Eplan.EplApi.Gui.Menu class and connects it to the MyScriptActionWithMenu action.
The same example in Visual Basic.Net looks like this:
Public Class RegisterScriptMenu <DeclareAction("MyScriptActionWithMenu")> _ Public Sub MyFunctionAsAction() MessageBox.Show("MyFunctionAsAction was called!", "RegisterScriptMenu") Return End Sub 'MyFunctionAsAction <DeclareMenu()> _ Public Sub MenuFunction() Dim oMenu As New Eplan.EplApi.Gui.Menu() oMenu.AddMenuItem("MyMenuText", "MyScriptActionWithMenu") End Sub 'MenuFunction End Class 'RegisterScriptMenu
See also