[Closed] Listbox items from a Getfilename
Hi there,
I’m just starting to get into Maxscripting and I’m trying to set up a script that will search a path (in this case the default Max renderpresets folder) and return all the .rps files into a listbox. I’m getting myself really confused doing this so I’ll post what I have below and we can all have a good laugh at how nonsensical it is:
Global theFiles = getFiles (GetDir #renderPresets + "[\\*.rps](file:///*.rps)")
Global filenames = #(for f in theFiles do (getFileNameFile f))
rollout RenderfloatObject "Render Presets"
(
listbox Rendersettings "Render Settings" width:201 height:12 items:#(filenames)
)
if varFloat != undefined then closeRolloutFloater varFloat
varFloat = newRollOutFloater "Test" 300 500
addRollout Renderfloatobject varfloat
This returns an error message:
Unable to convert: #(OK) to type: String
I know I’m way off the mark here, but I’ve been trying this all afternoon and can’t seem to get my head around it.
Any suggestions guys?
hi gary!
you need to build an array of shortened filenames to pass to the items parameter of the listbox, and as you have specifed it in the rollout construction, you need to do it before the rollout is defined -
Global theFiles = getFiles (GetDir #renderPresets +"\\*.rps")
Global filenames = #()
for f in theFiles do
(
local shortfile = getFileNameFile f
append filenames shortfile
)
rollout RenderfloatObject "Render Presets"
(
listbox Rendersettings "Render Settings" width:201 height:12 items:filenames
)
if varFloat != undefined then closeRolloutFloater varFloat
varFloat = newRollOutFloater "Test" 300 300
addRollout Renderfloatobject varfloat
you had put you loop inside the array so passed the result - OK (meaning it had completed the loop) into the array, not the actual file values themselves. the append function will grow the contents of an array with each loop.
it is asking for Unable to convert: #(OK) to type: String because the listbox needs an array of strings to display the list. getfilenamefile is a function that returns a string variable for the filepathstring you supply it, so after the array is built it can display these correctly.
if you look in the listener you will see that getfiles in your first line actually returns an array of strings, which would work in the listbox as you probably found out.
an alternative to LoneRobot’s solution would be:
filename = for f in theFiles collect getFileNameFile f
A for loop will return an array when you use it with the collect function. You were close! collect is super handy – I use it whenever possible.
NOTE: you can’t use do AND collect in the same for loop. its one or the other.
That’s fantastic guys, both solutions work a dream.
I had one or two other questions though, I was hoping you might have a suggestion…
I’ve tried recording the actions with the macro recorder, but I can’t seem to find a command for launching the ‘Launch Magnify Preview’ option in the material editor.
Alternatively, I’d love to be able to access the small material preview windows that are in the material editor and the material/map browser. I know it can be done (I think it’s done in the MatManager script) but I’ve no idea how… Maybe it creates a small preview jpg file for each material in a .mat file and stores them in a location?
I think that question maybe a bit over my abilities at the moment, I was just curious if there was a quick way to embed a small preview thumbnail into a window.
Thanks again guys,
Seems I got here a bit late…
Anyways, if you were still wondering (hope not):
The preview windows in MatManager are just standard bitmap GUI elements that “replicate” the behavior of the previews in the Material Editor. Currently there is no way to place preview windows in your own scripts (AFAIK).
The previews are generated by “silently” rendering the preview in the scene without the user noticing it and then storing it as a jpg file. When the user selects a material the script looks for the preview JPG and it renders it only if does not exist.