MAXScript provides a set of classes and functions and some special syntax to allow you to construct custom right-click menus that can be incorporated into the existing 3ds Max user interface. You typically use right-click menus to provide quick access to a selection of tools you have written in MAXScript. These tools would typically have no user interface, however you can create dialogs or rollout floater windows in a right-click menu to display a user interface.
A scripted right-click menu is created using the RCMenu definition construct in MAXScript, and then you register the right-click menu with 3ds Max. The top-level definition syntax is as follows:
rcmenu <var_name> ( <rcmenu_body> )
<var_name> is the name of an automatically created global variable to hold the rcmenu value that represents the right-click menu.
<rcmenu_body> is enclosed in the required parentheses and is a sequence of clauses that define the menu items that will appear in the utility, along with functions and event handlers that process user interactions. These clauses are defined in detail in RCMenu Clauses.
popUpMenu <RCMenu> [pos:<Point2>] [rollout:<Rollout>] [align:<key>]
This method will popup a menu anywhere on the screen. The controls are as follows:
<RCMenu>: Any RCMenu defined. It does not have to be registered.
[pos:<Point2>]: The point where the menu pops up, either relative to the Rollout or the screen. (Default: popup from current mouse position.)
[rollout:<Rollout>]: This will make the menu popup from a rollouts local coordinate system. Specifying undefined will cause the menu to popup relative to the upper left corner of the screen. (Default: undefined)
[align:<key>]: Can be one of the following (Default: #align_topleft):
Registers the specified right-click menu
Unregisters the specified right-click menu
Unregisters all right-click menus
The following script adds two items to the right-click menu: Cast Shadows and Receive Shadows. These items will be enabled only if one object is selected. If enabled, the items will be checked or unchecked based on the current state of the selected object. Choosing a menu item will flip the state of the corresponding object property.
menuItem mi_cs "Cast Shadows" checked:false
menuItem mi_rs "Receive Shadows" checked:false
on MyRCmenu open do
local sel = (selection.count == 1)
-- Enable if only one object is selected
mi_cs.enabled = mi_rs.enabled = sel
-- Set check state of items
if sel do
mi_cs.checked = $.castShadows
mi_rs.checked = $.receiveShadows
-- set up event handlers for items
on mi_cs picked do $.castShadows = (not $.castShadows)
on mi_rs picked do $.receiveShadows = (not $.receiveShadows)
-- register the rcmenu
You can register as many scripted right-click menus as you like. Each scripted right-click menu registered is appended to the right-click menu window. If a scripted right-click menu with the same name is registered twice, the old one is over written by the new one.
If a runtime error occurs while executing a scripted right-click menu, an error message is displayed in Listener. The right-click menu will not be disabled.