[Closed] change text on button pressed not work with undo
I have this script to change the name of the button when it’s pressed but not work with undo!
please i need a review . Thanks.
text1 = Btn_Snap.text
if text1 == “IK” then
(
Btn_Snap.text = “FK”
)
else Btn_Snap.text = “IK”
If you mean the 3ds Max Undo buffer, it only tracks scene changes.
There is no way to record the change of a button text via the Undo buffer.
The only case I could imagine where this would work would be if the button was showing a parameter of a scene object and you were using callbacks to track changes to that object and update the button’s text.
ouch!, thanks Bobo by request, so do you think if i could use the blending spinner parameter to do something like that without callbacks? for example if the spinner state is 100 do text1 and if the spinner is 0 do text2? sorry about my ignorance, im learning now maxscript and i like search my own requests but this is anything that appears easy and useful for show the state of my IK/FK button mode but… thanks!
rollout rol_ ""
(
button btn_1 "TEXT"
spinner spn_1 ""
on spn_1 changed val do
(
if val == 100 do btn_1.text = "Text 1"
if val == 0 do btn_1.text = "Text 0"
)
)
createdialog rol_
Ok, now the problem is: I want to use it in a snap IK FK button, so the value may change when the snap button is pressed not when the spinner value is changed. I have prove this lines in my snap button but not work. any idea?
Here is the snap code, it’s a normal snap code with case and value events
on Btn_Snap pressed do
with undo on
(
case $.modifiers[#Attribute_Holder].ARM_LEFT_CONTROLS[#Spn_Fk_Ik].value of
(
100.0:
(
--MATCH BUTTON FK TO IK--
------------------------------------------------------------------------------------------------------------------------------------------
--CUANDO PASO A FK--
--Set keys in actual and previews frame
sliderTime -= 1
$.modifiers[#Attribute_Holder].ARM_LEFT_CONTROLS.Spn_Fk_Ik = 100
sliderTime += 1
--SET FK / IK SPINNER VALUE TO 0 = FK
$.modifiers[#Attribute_Holder].ARM_LEFT_CONTROLS[#Spn_Fk_Ik].value=0
--ALIGN FK TO IK--
--Set Shoulder orientation control to IK
in coordsys $ST_Arm_Bone_IK_01_L$ST_Arm_Ctrl_Shoulder_L.rotation = eulerangles 0 0 0
--Set Elbow orientation control to IK
in coordsys $ST_Arm_Bone_IK_02_L$ST_Arm_Ctrl_Elbow_L.rotation = eulerangles 0 0 0
--Align hand orientation to wrist IK control
in coordsys $ST_Arm_Ctrl_Ik_L$ST_Arm_Hand_Root_FK_L.rotation = eulerangles 0 0 0
--Hide unhide controls
hide $ST_Arm_Ctrl_Ik_L
unhide $ST_Arm_Ctrl_Elbow_L
unhide $ST_Arm_Ctrl_Shoulder_L
unhide $ST_Arm_Hand_Root_FK_L
)
0.0:
(
--ALINEA LA IK A LA FK
-------------------------------------
--CUANDO PASO A IK
--Set keys in actual and previews frame
sliderTime -= 1
$.modifiers[#Attribute_Holder].ARM_LEFT_CONTROLS.Spn_Fk_Ik = 0
sliderTime += 1
--SET FK / IK SPINNER VALUE TO 0 = IK
if $.modifiers[#Attribute_Holder].ARM_LEFT_CONTROLS.Spn_Up_Stretch > 0 then
(
messagebox "Cannot switch to IK with FK stretched"
)
else
(
--Set wrist position control IK to FK
$ST_Arm_Ctrl_Ik_L.position = $ST_Arm_Point_Strch_FK_03_L.position
--Align Fk wrist control to IK
in coordsys $ST_Arm_Hand_Root_FK_L$ST_Arm_Ctrl_Ik_L.rotation = eulerangles 0 0 0
--Align Swivel IK to FK
$ST_Arm_SwivelAngle_IK_L.position = $ST_Arm_SwivelAngle_Align_FK_L.position
--Align control IK to Hand root
in coordsys $ST_Arm_Hand_Root_FK_L$ST_Arm_Ctrl_Ik_L.rotation = eulerangles 0 0 0
--Align swivel control
--Set FK / IK spinner to 100
$.modifiers[#Attribute_Holder].ARM_LEFT_CONTROLS[#Spn_Fk_Ik].value=100
--Hide Unhide controls
hide $ST_Arm_Hand_Root_FK_L
hide $ST_Arm_Ctrl_Elbow_L
hide $ST_Arm_Ctrl_Shoulder_L
unhide $ST_Arm_Ctrl_Ik_L
)
)
)
)
In the last code – what the button should show as a text – sliderTime values or case off values?
If the text must be sliderTime values put this after each sliderTime = +/-1
Btn_Snap.text = sliderTime.time as string
Maybe you want this:
on Btn_Snap pressed do
with undo on
(
case $.modifiers[#Attribute_Holder].ARM_LEFT_CONTROLS[#Spn_Fk_Ik].value of
(
100.0:
(
Btn_Snap.text = "100.0"
--MATCH BUTTON FK TO IK--
------------------------------------------------------------------------------------------------------------------------------------------
--CUANDO PASO A FK--
--Set keys in actual and previews frame
sliderTime -= 1
Btn_Snap.text = sliderTime.time as string
$.modifiers[#Attribute_Holder].ARM_LEFT_CONTROLS.Spn_Fk_Ik = 100
sliderTime += 1
Btn_Snap.text = sliderTime.time as string
--SET FK / IK SPINNER VALUE TO 0 = FK
$.modifiers[#Attribute_Holder].ARM_LEFT_CONTROLS[#Spn_Fk_Ik].value=0
--ALIGN FK TO IK--
--Set Shoulder orientation control to IK
in coordsys $ST_Arm_Bone_IK_01_L$ST_Arm_Ctrl_Shoulder_L.rotati on = eulerangles 0 0 0
--Set Elbow orientation control to IK
in coordsys $ST_Arm_Bone_IK_02_L$ST_Arm_Ctrl_Elbow_L.rotation = eulerangles 0 0 0
--Align hand orientation to wrist IK control
in coordsys $ST_Arm_Ctrl_Ik_L$ST_Arm_Hand_Root_FK_L.rotation = eulerangles 0 0 0
--Hide unhide controls
hide $ST_Arm_Ctrl_Ik_L
unhide $ST_Arm_Ctrl_Elbow_L
unhide $ST_Arm_Ctrl_Shoulder_L
unhide $ST_Arm_Hand_Root_FK_L
)
0.0:
(
Btn_Snap.text = "0.0"
--ALINEA LA IK A LA FK
-------------------------------------
--CUANDO PASO A IK
--Set keys in actual and previews frame
sliderTime -= 1
Btn_Snap.text = sliderTime.time as string
$.modifiers[#Attribute_Holder].ARM_LEFT_CONTROLS.Spn_Fk_Ik = 0
sliderTime += 1
Btn_Snap.text = sliderTime.time as string
--SET FK / IK SPINNER VALUE TO 0 = IK
if $.modifiers[#Attribute_Holder].ARM_LEFT_CONTROLS.Spn_Up_Stretch > 0 then
(
messagebox "Cannot switch to IK with FK stretched"
)
else
(
--Set wrist position control IK to FK
$ST_Arm_Ctrl_Ik_L.position = $ST_Arm_Point_Strch_FK_03_L.position
--Align Fk wrist control to IK
in coordsys $ST_Arm_Hand_Root_FK_L$ST_Arm_Ctrl_Ik_L.rotation = eulerangles 0 0 0
--Align Swivel IK to FK
$ST_Arm_SwivelAngle_IK_L.position = $ST_Arm_SwivelAngle_Align_FK_L.position
--Align control IK to Hand root
in coordsys $ST_Arm_Hand_Root_FK_L$ST_Arm_Ctrl_Ik_L.rotation = eulerangles 0 0 0
--Align swivel control
--Set FK / IK spinner to 100
$.modifiers[#Attribute_Holder].ARM_LEFT_CONTROLS[#Spn_Fk_Ik].value=100
--Hide Unhide controls
hide $ST_Arm_Hand_Root_FK_L
hide $ST_Arm_Ctrl_Elbow_L
hide $ST_Arm_Ctrl_Shoulder_L
unhide $ST_Arm_Ctrl_Ik_L
)
)
)
)
Or maybe not.
Thanks for reply, sorry I could have better explained…
The slider time lines its only a proccess in the code that generates the keys for the snap button to avoid them by hand. I have a button with the snap and the case event reference to the blend spinner :
case $.modifiers[#Attribute_Holder].ARM_LEFT_CONTROLS[#Spn_Fk_Ik].value of
Then my question is if I can use your code with the changed value event in this lines to change the text in the button, value 100 = IK value 0 = FK, everything carries me to callback event! the listener says that expect “when” but I have not been able. Thanks