View Full Version : Slider on change Event + Math + Logical Question

05 May 2009, 12:26 PM
I am using a slider where I set the range on the fly (through a variable)

myLayers = #(1,2,3,4,5,6,.....n) -- (This is calculated when the script runs)
mySlider.range = [0, myLayers.Count*5, 0]
mySlider.ticks = 5

Now lets say myLayers.count = 6. In this case the range will be 6*5 = 30... And with Ticks = 5 it will take 6 ticks to reach the range which is equal to myLayers.count.

In the "on Slider Changed Val" event I want play with each myLayers element visibility... So when the value of spinner is between 0-5 I want to increase the visibility of 1st element of myLayers from 0 to 100... when the value of spinner is betweek 5-10 I want to increase the visibility of Second element from 0 to 100... and so on.

This is what I cant quite put down correctly... any help will probably save me tons of hours. thanks

05 May 2009, 01:07 PM
Here is a quick example:

try (destroyDialog rollname) catch ()
rollout rollname "rollout"
spinner spNumLayers "num layers:" type:#integer range:[1,20,6]
slider slTest "test"
spinner spCurrentLayer "current layer:" enabled:false type:#integer range:[1,20,1]
spinner spVis "visibility:" enabled:false range:[0,100,0]

fn setTickes =
slTest.ticks = spNumLayers.value

fn getCurrentLayer =
spCurrentLayer.value = if slTest.value < 100 then
1 + spNumLayers.value * slTest.value / 100 as integer

fn getVisibility =
local part = 100.0 / spNumLayers.value
spVis.value = if slTest.value < 100 then
100 * (mod slTest.value part) / part

fn updateUI =

fn init =

-- Event Handlers

on spNumLayers changed val do setTickes()
on slTest changed val do updateUI()
on rollname open do init()

) -- end of rollout

createDialog rollname width:200

05 May 2009, 01:59 PM
thanks man. i think this will work... will get this working and post and update soon...

EDIT: Its Perfect. thankyou...

05 May 2009, 04:40 PM
i have run into a problem... although my script now works but its behaving in a wierd way

The visibility wont update on all objects when I am looking at only a Shaded View in viewport i.e. without wireframes.. But if I have wireframe + shaded it works fine....

How can I fix that?

CGTalk Moderation
05 May 2009, 04:40 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.