PDA

View Full Version : Get value from spinners in for loop.


Ojah
09-16-2009, 03:49 PM
Hi,

im trying to get the value of different spinners in a for loop, but whenever i try to get the spinners value by using execute this happens:
>> MAXScript Rollout Handler Exception: -- Unknown property: "value" in undefined <<

This is the piece of testcode im using atm:

rollout test "test"
(
spinner testSpinner1 "spin" type:#integer range:[0,100,100]
button getSpinValue "Button"
on getSpinValue pressed do
(
print (execute ("testSpinner" + 1 as string + ".value"))
)
)
createdialog test

I hope anyone can help me

edit: seems it doesnt work when i type: print (execute "testSpinner1.value") but it does work when type: print testSpinner1.value.
Its probably my lack of (max)scripting knowledge, but i dont really understand why the execute doesnt work here.

denisT
09-16-2009, 05:31 PM
Hi,

im trying to get the value of different spinners in a for loop, but whenever i try to get the spinners value by using execute this happens:
>> MAXScript Rollout Handler Exception: -- Unknown property: "value" in undefined <<

This is the piece of testcode im using atm:

rollout test "test"
(
spinner testSpinner1 "spin" type:#integer range:[0,100,100]
button getSpinValue "Button"
on getSpinValue pressed do
(
print (execute ("testSpinner" + 1 as string + ".value"))
)
)
createdialog test

I hope anyone can help me

edit: seems it doesnt work when i type: print (execute "testSpinner1.value") but it does work when type: print testSpinner1.value.
Its probably my lack of (max)scripting knowledge, but i dont really understand why the execute doesnt work here.

testSpinner is local ... execute function doesn't see it ... you have to use full path to the spinner:

rollout test "test"
(
spinner testSpinner1 "spin" type:#integer range:[0,100,100]
button getSpinValue "Button"
on getSpinValue pressed do
(
print (execute ("test.testSpinner" + 1 as string + ".value"))
)
)
createdialog test


but you don't need to use execute at all.
test.testSpinner.value gives you the spinner's value

Ojah
09-16-2009, 05:41 PM
haha awesome.

Thanks a lot!

I needed this because the 1 in this piece of code will be replaced with a number in a for loop.
It is used in a dynamic rollout that creates spinners (among other things) when a button is pressed.

Mathieson
09-16-2009, 05:51 PM
You can also use <rollout>.controls to get all controls existing in the rollout and then filter them to get exactly what spinners you are looking for. Here is a quick example.

rollout testR "test"
(
spinner testSpn1
spinner testSpn2
edittext testEt1
button testBtn "Update Spinner Values"

on testBtn pressed do
(
local spns = for x in testR.controls where classOf x == spinnercontrol collect x

format "Here are the spinner controls:\n"
print spns

spns.value = 10
)
)
createDialog testR

denisT
09-16-2009, 06:00 PM
or ...

(getproperty test ("testSpinner" + <id> as string)).value

Ojah
09-16-2009, 07:08 PM
Thanks again!

Never used classof to identify a ui item before, didnt cross my mind actually, but seems usefull in the script Im trying to create.
I tried using getproperty, but when I try to set a property afterwards with setproperty in the same way I can't get it to work.

But have to say, Im really gratefull, learning lots of new stuff here :)

denisT
09-16-2009, 07:26 PM
I tried using getproperty, but when I try to set a property afterwards with setproperty in the same way I can't get it to work.


to set property:

((getproperty test ("testSpinner" + <id> as string)).value = <...>
-- or
setprorepty (getproperty test ("testSpinner" + <id> as string)) #value <...>

Mathieson
09-16-2009, 08:25 PM
or ...

(getproperty test ("testSpinner" + <id> as string)).value


Hadn't thought of that. Good call!

CGTalk Moderation
09-16-2009, 08:25 PM
This thread has been automatically closed as it remained inactive for 12 months. If you wish to continue the discussion, please create a new thread in the appropriate forum.