Array names, to string for UI name

Heya

I want to use name from folder as a string for button. Can some1 help me out? I'm stuck at last part. The script wont accept the file I picked as name :(

rollout lel "Untitled" width:312 height:305
(
	global lis = #()
        global cn = #()
 
	button btn1 cn[1] pos:[51,22] width:200 height:59
 
	button btn2 cn[2] pos:[48,106] width:200 height:59
	on lel open do
	(
		allFiles = getFiles ("C:\Test\Cams\\" + "\\*.max")
		lis = allFiles
		for data in lis do
		( 	da = filterString data "\\"
			aa =substituteString da[4] "-" ""
			BB = substring aa 1 (aa.count-4)
			append  cn(BB)
			)
 
)
)
theNewFloater = newRolloutFloater "Test" 338 800
addRollout lel theNewFloater

Comments

Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
Dariusz's picture

Nope getting error :>>

Nope getting error :

>> MAXScript Rollout Handler Exception:
-- Unable to convert: undefined to type: String <<

Normally in python I would've type str(cn[1]) instead of cn[1] I just dont know how to do it in maxscriot :(

pixamoon's picture

hey,

Hey,

Yes, cn[1] and cn[2] are undefined... on creation of rollout

you need to define them first as anything:

local cn = #("Button1", "Button2")
--or
local cn = #("","")

and then after you get filenames from hdd change buttons text:

btn1.text = lis[1]
btn2.text = lis[2]

This should be it I think...

PS. As mentioned before... don't use "globals" in those cases. "locals" are enough.
Globals should be used more to transit variables between scripts or to keep values to the next time you open script etc...

barigazy's picture

...

Declare your rollout as global variable by using global or :: sign.
U can call any local var or function inside rollout (see example). Rollout here
act like "struct" (in python this will be "class").U can find some examples related to struct in mxs help document

try(destroyDialog ::test1Roll)catch()
rollout test1Roll "test1Roll"
(
	local VAR = "Some string"
 
	button btn "New roll" pos:[5,5] width:90 height:18
	on btn pressed do 
	(
		try(destroyDialog ::test2Roll)catch()
		rollout test2Roll "test2Roll"
		(
			button btn2 "Print var" pos:[5,5] width:90 height:18
			on btn2 pressed do 
			(
				print test1Roll.var
			)
		)
		createDialog test2Roll 100 30 style:#(#style_titlebar, #style_sysmenu, #style_toolwindow)
	)
)
createDialog test1Roll 100 30 style:#(#style_titlebar, #style_sysmenu, #style_toolwindow)

bga

barigazy's picture

...

Try like this

allFiles = getFiles (@"C:\Test\Cams\\" + "\\*.max")

bga

Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.