[Closed] RC Menu
As I said somebody can ofer you a better solution.
My way also work, but again you make one mistake. In my example I use:
fn fnRunScript s e = --Run the selected script
(
fileIn (fullPath+s.name+".ms")
)
but you again post a code that use
fn fnRunScript s e = --Run the selected script
(
fileIn s.name
)
Using
fileIn s.name
make no sense to have fullPath variable.
I must have overlooked that line.
I’m going see what I can do with this tag property and ill be sure to post it so everyone can use it and see it.
How do i get the popup menu to just show on evaluation of the script. Right now when I evaluate it I have to right click in the dialog?
Because I want to then make it a macro and have it has a hotkey or button in the shelf.
John
Here is the final code all together and working.
Now do anyone know how I could make this into a macro/hotkey so when you hit the key the RCMenu shows…not the form/dialog?
Right now you have to right click in the dialog for the RCMenu to appear, I want to be able to hit a hotkey or a toolbar button that will make it appear.
(
local fullPath = undefined
dir = @"C:\Users\Crabs User\Desktop estScripts" --//Main Scripts directory
dirArray = GetDirectories (dir+"/*") --//Get subfolders in directory
foldersArray = for d in dirArray collect (trimright (filenameFromPath d) "\\") --//Array which stores just the names of the subfolders
form = dotnetobject "MaxCustomControls.Maxform"
form.Text = "Dynamic ContextMenu"
cm = dotNetObject "ContextMenu"
form.ContextMenu = cm
for i in foldersArray do
(
item = cm.menuitems.add i
item.name = i
)
fn onPopup s e =
(
for b = 1 to foldersArray.count do
(
i = (s.menuitems.Find (foldersArray[b] as string) off)[1]
i.menuitems.clear()
sFiles = #()
sFiles = getFiles (dirArray[b] + "*.ms*")
fn fnRunScript s e = --Run the selected script
(
--fileIn s.name
fileIn (s.tag)
)
if sFiles.count > 0 then --//Add the scripts to appropriate list
(
for n in sFiles do
(
scriptName = getFIleNameFile n
item = i.menuitems.add scriptName
item.name = scriptName
item.tag = n -- variable "n" contains the fullpath extention
dotnet.addEventHandler item "Click" fnRunScript
)
)
else
(
item = i.menuitems.add "No Scripts"
item.enabled = off
)
)
)
dotnet.addEventHandler cm "Popup" onPopup
form.showmodeless()
)
macroscript Popup_Menu category:"denisT" buttonText:"DRC" tooltip:"Popup RC"
(
local form = dotnetobject "MaxCustomControls.Maxform"
form.ShowInTaskbar = off
form.FormBorderStyle = form.FormBorderStyle.None
form.AllowTransparency = on
form.Opacity = 0
-- form.TransparencyKey = form.Backcolor
form.StartPosition = form.StartPosition.Manual
form.Size = Form.MinimumSize
form.Location = dotnetobject "System.Drawing.Point" 500 300
local cm = dotNetObject "ContextMenu"
local i = cm.menuitems.Add "Create"
(
i.menuitems.Add "Box"
i.menuitems.Add "Sphere"
i.menuitems.Add "Cone"
)
form.ContextMenu = cm
fn onCollapse s e =
(
s.SourceControl.Hide()
-- s.SourceControl.Dispose()
)
dotnet.addEventHandler cm "Collapse" onCollapse
fn onShown s e =
(
s.ContextMenu.Show s (dotnetobject "System.Drawing.Point" 0 0)
)
dotnet.addEventHandler form "Shown" onShown
local opened = off
on isChecked do return opened
on isEnabled do return (not opened)
on execute do
(
opened = not opened
if opened do
(
updateToolbarButtons()
form.ShowDialog()
opened = off
)
)
)