Organizing scripts in customui

 From:  Michael Gibson
12127.5 In reply to 12127.3 
Hi Barry, thanks for posting the screenshots and your script code.

Ok, so the sub menu opening on the bottom right of the screen is from passing moi.ui.commandBar.CommandBarCustomUI as the parent element of the menu.

The menu will show being connected to the screen rectangle of the parent element. The element you are passing, CommandBarCustomUI, is the container of all the custom buttons in the bottom command bar. You usually want to pass in the button element that is being clicked on. That will be easier to get if you use an onclick="" event handler on the <moi:MenuItem> instead of having a command="" attribute with script inside it instead of a command name.

For an onclick="" event handler you will be able to use the 'this' keyword to refer to the element that was clicked on.

Then there's an additional tricky thing which is that by default most elements will automatically dismiss the flyout they are inside when they are clicked. That will interfere with launching a sub menu coming off of another flyout menu like you want here. So you'll need to put a style property dismissFlyout:false on the MenuItem also.

So try this for making your sub-menu links:

document.write('<moi:MenuItem style="dismissFlyout:false" onclick="moi.ui.showMenu(\'moi://appdata/customui/ScriptsCategory_SOL.menu.htm\', this, 1, 0);">Solids ></moi:MenuItem>');


The 3rd and 4th arguments to moi.ui.showMenu control how the menu will attach to the parent element's rectangle.

The 3rd argument is for LaunchSide which can be 0, 1, 2, 3 The 4th argument is for LaunchDir which can be 0 or 1.

The menu connection will go like this:

LaunchSide 0 Flyout has connector at its top, expanding to the right if LaunchDir == 0 or expanding to left if LaunchDir != 0

LaunchSide 1 Flyout has a connector on its left, expanding down if LaunchDir == 0 or up if LaunchDir != 0

LaunchSide 2 Flyout has a connector on its bottom, expanding right or left

LaunchSide 3 Flyout has a connector on its right, expanding down or up.

So if you pass in LaunchSide 1, LaunchDir 0 it will make the menu with the connector on the menu's left (so to the right of the parent element), expanding down, like this example in the Options dialog under Snaps:



Hope this helps! - Michael
Attachments: