[Closed] updating spinner on selection
hi,
in my current script I have a rollout with spinners that should return the (local) pivotposition of the selected object, so I need to update the value on a changed selection.
I have been using a timer so far, to update every second, but I saw a piece about Callbacks.addscript #selectionsetchanged on this forum, which should provide a better solution.
But of course i cannot get it to work.
I can get the callback to alter a global variable, but i cannot get the variable into the spinner without an “on …” and I would like it to update without touching the rollout or using a timer.
The spinners have a .value property that you can change from your callback. Here is a simple code that demonstrates that:
rollout rlt_test "test"
(
spinner spn_x "X: " range:[-100000.0,100000.0,0.0] type:#float fieldWidth:100 align:#left
spinner spn_y "Y: " range:[-100000.0,100000.0,0.0] type:#float fieldWidth:100 align:#left
spinner spn_z "Z: " range:[-100000.0,100000.0,0.0] type:#float fieldWidth:100 align:#left
button btn_update "Update Spinners"
on rlt_test open do
(
spn_x.value = selection[1].pos.x
spn_y.value = selection[1].pos.y
spn_z.value = selection[1].pos.z
)
on btn_update pressed do
(
spn_x.value = selection[1].pos.x
spn_y.value = selection[1].pos.y
spn_z.value = selection[1].pos.z
)
)
createdialog rlt_test 150 150
For the example to work you must have one object selected and when you move it press the Update button to update the spinner’s value.
You will have to set your spinner .value property from your callback, the way I did it was through the press of a button just to keep the example simple.
Hope this helps.
thanks, but this is something I have already done. My problem is just getting the callback to work with the spinner so I dont have to click something or use the not-so-nice timer workaround.
you may need the callback to access the rollout/dialog directly – i.e
dialogname.spinnername.value
the callback will change the spinner via the value property and is not neccesary to invoke the handler
Great! thanks a lot, works like a charm.
(used the following code for testing, in case anyone is interested)
rollout blaat "blaat"
(
spinner blaspin "spinnerr " range:[0,200,0]
)
blaatFloat = newRolloutFloater "blahaat" 200 500
addRollout blaat blaatFloat
callbacks.addscript #selectionSetChanged "blaat.blaspin.value = blaat.blaspin.value + 1" id:#abcd
you might find it better to register a function containing the code that you wish to perform. It’s not neccesary in this case, but it will be easier to control when you want to perform more things with the callback.
ie –
fn dointhasheeyat =
(
blaat.blaspin.value = blaat.blaspin.value + 1
– all the other stuffage you want to do ever in the the whole world –
)
callbacks.addscript #selectionSetChanged “dointhesheeyat()” id:#abc
Thanks a lot again
this was indeed something that i was planning to do, as the script is becoming larger and larger.