View Full Version : How to perform script when slider manipulator value changes?
AnimG 02-15-2007, 12:17 PM Hi
I have many slider manipulators in my scene and as they clutter up the viewport I decided to add a master slider that based on its value 0.0 or 1.0 would hide/unhide the other sliders.
But I cant figure out how to evaluate the "value" of the slider when the user changes it?
Any help it doing this please?
Thanks
Anim
|
|
Jon-Huhn
02-15-2007, 01:46 PM
If it's just a boolean value you're trying to detect, would it be easier to just run the script as a UI button?
AnimG
02-15-2007, 04:12 PM
Yup, it would be much easier if I could just use a script and drag it to the toolbar but thats not what I need for this particular model. Its a uni project that can only use slider manipulators to keep it simple and the hand in is just a max file.
It might not be possible to be honest, i've tried using wiring but couldn't discover a way to evaluate "value" within the wiring dialog, I can only apply new values.
Thanks anyway
Anim
AnimG
02-15-2007, 04:14 PM
Additionaly I could add a Float Script controller to the Value of a slider but that then removed all interactivity.
juako
02-15-2007, 04:31 PM
you know i have the same problem , don't know how tho check user interaction
then its easy
for example you would need an if statement
if ( sliderval == 1) then
(
hide the objects you want
)
else
(
unhide the objects you want
)
something like that
but how truck the user changes
PiXeL_MoNKeY
02-15-2007, 05:28 PM
What about trying a change handler on the parameters of the master slider?
This will leave the ability to move them, but removes the labels and sliders.when parameters <MasterSlider> changes do (if <MasterSlider>.value == 1.0 then (<Slider>.hide = on) else (<Slider>.hide = off))This hides the Slider at the node level.when parameters <MasterSlider> changes do (if <MasterSlider>.value == 1.0 then (<Slider>.ishidden = true) else (<Slider>.ishidden = false))
Hope this helps some,
-Eric
jonlauf
02-15-2007, 07:03 PM
This script creates a slider and 5 rectangles, hides the rectangles when the slider reaches 100.0 and unhides them when the value of the slider is < 100.0. Hope it helps
recArray = #()
theSlider = sliderManipulator xpos:.1 ypos:.48
for i = 1 to 5 do
(
theRec = rectangle length:20 width:20
theRec.pos.x = i*25
rotate theRec (eulerangles 90 0 0)
theRec.wirecolor = yellow
append recArray theRec
)
when parameters theSlider changes do
(
if theSlider.value == 100.0 then
(
for i in recArray do (hide i)
)
if theSlider.value < 100.0 then
(
for i in recArray do (unhide i)
)
)
juako
02-15-2007, 07:23 PM
theirs any way that save the when statement .
because if yo save the scene and then re open it you will find that the script doesnt work any more.
PiXeL_MoNKeY
02-15-2007, 08:14 PM
Yes you can make it a persistent global. This will embed the change handler into the scene.
a = when parameters <MasterSlider> changes do (
if <MasterSlider>.value == 1.0 then (
<Slider>.ishidden = true
)
else (
<Slider>.ishidden = false
)
)
persistent global a
-Eric
AnimG
02-15-2007, 08:42 PM
Some promising responses there, thanks guys.
Am I right in thinking that simply evaluating the script in my scene with the "persistent global a" will somehow embed it into the max file without the need for a seperate ms file or attaching it to an object in some manner?
If so then that is fantastic.
Cheers
Anim
PiXeL_MoNKeY
02-15-2007, 09:05 PM
That is correct, as long as you define the script as the variable "a". To verifiy if it is in the scene you can run "persistents.show()".
-Eric
juako
02-15-2007, 09:22 PM
THANKS PiXeL_MoNKeYi only have one problem when i run the script i get this when i use persistents.show()
a: <ChangeHandler:0x00003518>
but when i save and re open the script doesn't work any more an i get this when i use persistents.show()
a: $Slider:Slider01 @ [15.605563,-14.312077,0.000000]
any idea what I'm doing wrong
a = (whenparameters $Slider01 changes do (
if Slider01.value == 1.0 then (
$Sphere02.ishidden = true
)
else (
$Sphere02.ishidden = false
)
))
persistentglobal a
AnimG
02-16-2007, 08:03 AM
Same problem here, the command "persistent global hideSliders" does not seem to save this code to a state that can be reused when the file is reopened at a later date.
hideSliders = when parameters $Slider01 changes do (
if $Slider01.value == 1.0 then (
$Slider02.ishidden = true
$Slider03.ishidden = true
)
else (
$Slider02.ishidden = false
$Slider03.ishidden = false
)
)
persistent global hideSliders
AnimG
02-16-2007, 08:22 AM
isn't there anyway to make an embedded script run when a scene opens?
The code to hide the sliders works great but I just need this to be usable when the scene opens on somebody elses computer.
Frustrating that something as simple as this is difficult to do.
Anim
PiXeL_MoNKeY
02-16-2007, 03:31 PM
Look at the callback system in maxscript and use a #filepostopen command. This will execute the code after the file is open.
-Eric
Edit:Here is an example that will create 6 sliders 5 of which are linked to the $MasterSlider.value to hide if > 100. The first when statement executes the command in the current scene, and the #filepostopen callback embeds it in the scene and will execute everytime the scene is opened.MasterSlider = sliderManipulator xpos:.025 ypos:.1 name:"MasterSlider"
sldrArr = #()
for i = 1 to 5 do
(
sldr = copy MasterSlider
sldr.name = "Slider_0" + (i as string)
sldr.ypos += (i*.075)
append sldrArr sldr
)
when parameters $MasterSlider changes do (
if $MasterSlider.value == 100.0 then (
for i in sldrArr do (hide i)
)
if $MasterSlider.value < 100.0 then (
for i in sldrArr do (unhide i)
)
)
callbacks.addscript #filePostOpen "sldrArr = #() for sldr in $Slider* do append sldrArr sldr; when parameters $MasterSlider changes do (if $MasterSlider.value == 100.0 then (for i in sldrArr do (hide i)) if $MasterSlider.value < 100.0 then (for i in sldrArr do (unhide i)))" id:#sldrhide persistent:true
AnimG
02-16-2007, 07:24 PM
Hi Pixel monkey
Does this work on your machine?
I tried your example script (max 9), saved the scene to a file, closed max, opened max, opened the scene, tried the sliders and they didnt work.
Any ideas?
Cheers
Anim
PiXeL_MoNKeY
02-16-2007, 07:38 PM
What do you mean by the sliders didn't work? Only the top slider will do anything with that script.
-Eric
edit: I forgot the persistent:true at the end of the script. This makes the callback stick in teh max file. I updated the pervious script with it.
AnimG
02-16-2007, 09:19 PM
YES!
:bounce:
Pixel Monkey, your a star!
CGTalk Moderation
02-16-2007, 09:19 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.
vBulletin v3.0.5, Copyright ©2000-2012, Jelsoft Enterprises Ltd.