PDA

View Full Version : dotNet dropdownlist


JokerMartini
02-15-2012, 04:10 PM
Revisiting a script that was built a while back. I'm not sure what I am missing but it does not seem to properly open the script when it is clicked in the dialog. All this script does is create a dropdownlist of ms based on a targeted folder.



macroscript Popup_Menu category:"Custom" buttonText:"IETools" tooltip:"IETools"
(
local fullPath = undefined
dir = @"Q:\ASSETS\Tools\_dev\Max\scripts" --//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

local cm = dotNetObject "System.Windows.Forms.ContextMenuStrip"
local cursor = dotNetClass "System.Windows.Forms.Cursor"

for i in foldersArray do
(
item = cm.Items.Add i
item.name = i
)

fn onPopup s e =
(
for b = 1 to foldersArray.count do
(
i = (s.Items.Find (foldersArray[b] as string) off)[1]
i.DropDownItems.Clear()

sFiles = #()
sFiles = getFiles (dirArray[b] + "*.ms*")

fn fnRunScript s e = --Run the selected script
(
fileIn (s.tag)
)

if sFiles.count > 0 then --//Add the scripts to appropriate list
(
for n in sFiles do
(
scriptName = getFIleNameFile n
item = i.DropDownItems.Add scriptName
item.name = scriptName
item.tag = n -- variable "n" contains the fullpath extention

dotnet.addEventHandler item "Click" fnRunScript
)
)
else
(
item = i.DropDownItems.Add "No Scripts"
item.enabled = off
)
)
)
dotnet.addEventHandler cm "Opening" onPopup

on execute do
(
cm.Show(cursor.Position)
)
)

CGTalk Moderation
02-15-2012, 04:10 PM
This thread has been automatically closed as it remained inactive for 12 months. If you wish to continue the discussion, please create a new thread in the appropriate forum.