ScriptSpot

Forum topic · General Scripting

Calling a variable with another variable

By rosuto · 2012-06-24

Description

Im wondering if there is an easier way to go through my UI variables instead of doing it one at a time. For example, I have 40 text boxes and I named the boxes by increasing number, text1, text2 ... text39, text40. Instead of writing out 40 lines of code to get the information in every text box, I was hoping to do something like

for f=1 to 40 do (
append textArray textf.text
)

Ive tried ("text" + f as string) as object
That didnt work. Is this even possible in maxscript or am I stuck working with a very long script?

Comments (5)

jos · 2012-06-24

this is what you need right?


rollout roll_test "Test"
(
	edittext edt1
	edittext edt2
	edittext edt3
	edittext edt4
	edittext edt5
	button btnPrint "Print values"
	
	local edtArr = #(edt1,edt2,edt3,edt4,edt5)
	
	on btnPrint pressed do
	(
		for edt in edtArr do print edt.text
	)
)
createDialog roll_test

Thats it

rosuto · 2012-06-24

Thanks. Works perfectly

miauu · 2012-06-24

Create new empty scene, create 5 boxes and execute this code


$Box*.count

In the listenre will be printed 5

Do you have objects, which names start with "textbox". If you don't have it, the result from


print $textbox*.count

will give you 0.
If your objects name are:
01_textbox_001
02_textbox_002
then to get all objects with string "textbox" in the names you have to use


print $*textbox*.count

rosuto · 2012-06-24

I can only seem to get that to work with modeling objects.

print $textbox*.count gives me 0

Soemthing like this:

miauu · 2012-06-24


(
	--	method 1
	boxArr = $Box*	-->	collect all objects which names starts with "Box"
	for i = 1 to boxArr.count do print boxArr[i].name
	--	method 2
	for i in $Box* do print i.name	
)