[Closed] checkbox enabled state
Hi. I’m probably missing a basic here. If i add a checkbox as a custom attribute to one of my scene objects how can i permanently change the enabled state? Right now changing the enabled state has only effect as long as i keep the object selected, if I deselect and reselect the enabled state is back to where it was before…
-- creates a box with a disabled checkbox and a button to enable it.
b = box()
addmodifier b (emptyModifier())
ca = attributes test_ca
(
rollout test_rl "test"
(
checkbox test_cb "test" enabled:false
button enable_btn "enable"
on enable_btn pressed do test_cb.enabled = true
)
)
custAttributes.add b.modifiers[1] ca
Hi,
the rollout is created each time you display the CA’s UI,
and you explicitely define the checkbox disabled.
you need to store the enabled state in the CA
b = box()
addmodifier b (emptyModifier())
ca = attributes test_ca
(
parameters main rollout:test_rl
(
test_cb_enable type:#boolean
)
rollout test_rl "test"
(
checkbox test_cb "test" enabled:test_cb_enable
button enable_btn "enable"
on enable_btn pressed do test_cb.enabled = test_cb_enable = true
)
)
I was late, ZBuffer got the first place (hi buddy). As he said you need to create parameters to store data in a permanent way. In this example you got one to store the checkbox enabled state, and another one automatically tied to the UI element to save its checked state.
b = box()
addmodifier b (emptyModifier())
ca = attributes test_ca
(
local test_rl
parameters main rollout:test_rl
(
test_cb_state type:#boolean default:false
test_cb_value type:#boolean ui:test_cb default:false
)
rollout test_rl "test"
(
checkbox test_cb "test" enabled:test_cb_state
button enable_btn "enable"
on enable_btn pressed do
(
test_cb_state = true
test_cb.enabled = test_cb_state
)
)
)
custAttributes.add b.modifiers[1] ca
- Enrico
Ah. I initially thought it would need to be that way, but i couldn’t fugure out the syntax. Thank you both. You helped me a lot.
with using of SET event you can bind param block parameter and UI control parameter(s):
(
-- delete objects
b = box isselected:on
m = emptyModifier()
addmodifier b m
ca = attributes test_ca
(
parameters main rollout:test_rl
(
test_cb_enable type:#boolean default:off
on test_cb_enable set val do this.test_rl.test_cb.enabled = val
)
rollout test_rl "test"
(
checkbox test_cb "test" enabled:test_cb_enable
button enable_btn "enable"
on enable_btn pressed do test_cb_enable = not test_cb_enable
)
)
CustAttributes.add m ca
m.test_cb_enable = not m.test_cb_enable
)
How cool is that. You can have event handlers inside the param-block, too. This is great information to me. I will probably use those constantly in future scripts.