[Closed] I need help with a simple thing, I guess
I try to build a script that holds, among other controls, a radiobutton and a multilistbox.
The radiobutton will have different options, for example;
radiobuttons list_files labels:#(“1”, “2”, “3”)
- 1
- 2
- 3
If the user select 1, the multilistbox will display all maxfiles in c:\files\1
If the user select 2, the multilistbox will display all maxfiles in c:\files\2
If the user select 3, the multilistbox will display all maxfiles in c:\files\3
How do I code this? Is it possible to do this with a radiobutton?
Thanks for any help.
Regards
/*
-- make test directory --
makedir @"c: emp\max\work est\"
makedir @"c: emp\max emp\"
savemaxfile @"c: emp\max\work\a.max" quiet:on
savemaxfile @"c: emp\max\work\b.max" quiet:on
savemaxfile @"c: emp\max\work\c.max" quiet:on
savemaxfile @"c: emp\max emp\d.max" quiet:on
savemaxfile @"c: emp\max emp\e.max" quiet:on
savemaxfile @"c: emp\max emp\f.max" quiet:on
savemaxfile @"c: emp\max\work est\g.max" quiet:on
savemaxfile @"c: emp\max\work est\h.max" quiet:on
*/
this is how to make it with radiobuttons concept:
try(destroydialog fileExplorer) catch()
rollout fileExplorer "File Explorer" width:200
(
local folders =
#(
@"c: emp\max\work\",
@"c: emp\max emp\",
@"c: emp\max\work est\"
)
radiobuttons active_rb "Active Folder:" labels:#("Work ", "Temp", "Test") columns:3 align:#left offset:[14,0]
edittext folder_ed readonly:on width:194 align:#left offset:[-12,0]
listbox files_lb width:190 height:20 align:#left offset:[-8,-2]
fn updateUI state: =
(
if state != unsupplied then active_rb.state = state else state = active_rb.state
folder_ed.text = folders[state]
files = for f in getfiles (folders[state] + "*.max") collect filenamefrompath f
files_lb.items = files
)
on active_rb changed state do updateUI()
on fileExplorer open do updateUI()
)
createdialog fileExplorer
but a pro way is to use dropdown list:
try(destroydialog fileExplorer) catch()
rollout fileExplorer "File Explorer" width:200
(
local folders =
#(
@"c: emp\max\work\",
@"c: emp\max emp\",
@"c: emp\max\work est\"
)
dropdownlist folders_dd "Active Folder:" items:folders width:190 align:#left offset:[-8,0]
listbox files_lb width:190 height:20 align:#left offset:[-8,-2]
fn updateUI index: =
(
if index != unsupplied then folders_dd.selection = index else index = folders_dd.selection
files = for f in getfiles (folders[index] + "*.max") collect filenamefrompath f
files_lb.items = files
)
on folders_dd selected index do updateUI()
on fileExplorer open do updateUI()
)
createdialog fileExplorer
(
global rol_test
try(destroyDialog rol_test)catch()
rollout rol_test ""
(
local filesArr01 = #("C:\1\file011","C:\1\file021","C:\1\file013")
local filesArr02 = #("C:\2\file021","C:\2\file022","C:\2\file023")
local filesArr03 = #("C:\3\file031","C:\3\file032","C:\3\file033")
multiListBox mlb_01 "Files" items:#()
radiobuttons rb_list_files labels:#("1", "2", "3")
on rb_list_files changed state do
(
case rb_list_files.state of
(
1: (mlb_01.items = filesArr01)
2: (mlb_01.items = filesArr02)
3: (mlb_01.items = filesArr03)
)
)
)
createdialog rol_test
)
Big thanks miauu, really great, I will try it as soon as I come home
But there is one question in the code I don’t understand:
local filesArr01 = #(“C:\1\file011”,“C:\1\file021”,“C:\1\file013”)
The directory is clear: C:\1, but after that, file011, file021 and file013.
What are this used for?
Can’t it be written like this:
local filesArr01 = #(“C:\1”)
Im still learning MaxScript, so sorry for my stupid questions
This
local filesArr01 = #("C:\1\file011","C:\1\file021","C:\1\file013")
is just an example. file_011 can be directory or file name. You know what it will be in your script.
This
local filesArr01 = #("C:\1\")
is a path to directory. It will not collect all files in that directory.
If you have UI for the script then you can have buttons with which you can get all files in specificd directory.
If your directory will be persistent then you can use this:
local filesArr01 = getFiles "C:\\1\\*.max"
to collect all max files in the “1” directory. Then the multilistbox will shows those file paths.
the dropdown list solution is not limited by ‘reasonable’ number of choices… the radiobuttons usually looks ok in range of number labels 2-6. more than 6 labels looks as mess.
also the dropdown solution can be easily extended to work with dynamic list of folders (add new, remove old, etc.).
Wow, this is so great folks, big thanks to all of you. This is exactly what I needed and it helped me out a lot. Can’t thank you enogh!
Cheers