|
Onetastic Macro Documentation >
>
Macro menus
Each macro adds a button to the ribbon to run the macro. Optionally, macros can display a menu in the ribbon for more options. For example, Function macro displays the following menu:

Macro menus can be static or dynamically generated based on user's usage patterns. For instance a macro like Search and Replace may display the recently used search and replace terms in the menu.
Setup function
Both static and dynamic menus are created by the Setup function. Setup function is a user defined function in a macro which will get called whenever Onetastic needs to get a macro's menu to be displayed in the ribbon. Below is a sample Setup function:
Copied!
function Setup(byref $menu)
MacroMenu_AddItem($menu, "arg1", "Menu Item 1", "Description for Menu Item 1")
MacroMenu_AddItem($menu, "arg2", "Menu Item 2", "Description for Menu Item 2")
MacroMenu_AddItem($menu, "arg3", "Menu Item 3", "Description for Menu Item 3")
Setup function always has a single parameter byref $menu. This parameter is an object of type MacroMenu. You can then use the MacroMenu_AddItem function to add menu items. A macro with this Setup function will have the following menu:

Each menu item is associated with an argument that will be passed to Main function when user clicks on that menu item. In this case if user clicks the first menu item, Main function for this macro will be called with the argument arg1.
Performance Considerations
Setup function will get called every time Onetastic needs to refresh the menu for each macro. This can be after a macro execution, after a macro is edited, or after a new macro is downloaded. To avoid performance problems, Setup function should do minimal work and should not be running for a long time. Setup function for a macro will get aborted if it runs long and the menu for that macro will not be visible. Setup function also cannot access OneNote content or show dialog boxes.
Creating and Editing Setup Function
Macro editor makes it easy to create a setup function quickly via the following menu:

This will create a sample Setup function which you can use to quickly edit. If a Setup function already exists, this will switch to it.
Debugging Menu Items
As macro menu items pass arguments to the main function, you may want to debug the execution of your macro with such arguments. The debug button in the Macro Editor toolbar has a split menu that makes it easy to pick the menu items and debug their execution:

This menu will display each menu item and clicking on one of them will start the debugger with the associated argument passed to the Main function.
|