ScriptSpot

Forum topic · General Scripting

Changing directories with an array

By alexcfarrell · 2012-12-15

Description

Hi, I'm tring to write a script that will access material libraries from different folders (much like Sigershader's VMPP). My first listbox is populated by an array of Material Categories and are defined as such...


MatSections = #()
append MatSections #("Metal","C:\Users\Alex\Documents\3dsMax\materiallibraries\Metal\\")
append MatSections #("Wood","C:\Users\Alex\Documents\3dsMax\materiallibraries\Wood\\")
append MatSections #("Glass","C:\Users\Alex\Documents\3dsMax\materiallibraries\Glass\\")

Which currently works. When I select an item in this listbox, I want the second listbox to be populated with a list of the matlibs that reside in the relevant folder. Here's what I have so far...


	on lbx_MatSection selected itm do
		(
		MatCatPath = getFiles "((MatSections[objList.selection][2])"+"*.mat")
		MatCatFiles = for i in MatCatPath collect ( filenamefrompath i )
		lbx_MatCat.items = MatCatFiles
)

Which doesn't work. I get an error saying "-- Syntax error: at =, expected name". Previously I had a simpler script that just loaded all matlibs from a folder (which worked)...


		allMatLibs = getFiles "C:\Users\Alex\Documents\3dsMax\materiallibraries\*.mat"
		list = for i in allMatLibs collect (getFilenameFile i)
		lbx_MatSection.items = list

But it was too simple for what I need now. Basically I'm trying to get the two bits of code to work together but I'm struggling, so any help would be greatly appreciated. Cheers,
Alex

Comments (4)

alexcfarrell · 2012-12-15

Brilliant! Cheers for the help guys. Thought it would be a simple syntax issue, also would have helped if I renamed objList.selection to lbx_MatSection.selection! And thanks for the script recommendation Barigazy, looks really useful.
Thanks again.

Perfect_Storm · 2012-12-15

MatCatPath = getFiles "((MatSections[objList.selection][2])"+"*.mat")

You mistyped the (, it should be in front of the ":

MatCatPath = getFiles ("(MatSections[objList.selection][2])"+"*.mat")

MatCatPath = getFiles

br0t · 2012-12-15


MatCatPath = getFiles "((MatSections[objList.selection][2])"+"*.mat")

That line is wrong, isnt it? Why the quotation marks after getFiles? Maybe more like this:


MatCatPath = getFiles ((MatSections[objList.selection][2]) + "*.mat")