Home Marmoset

Marmoset's Python->"onChange"

polycounter lvl 6
Offline / Send Message
goekbenjamin polycounter lvl 6
when using "UISliderFloat->onChange"
how can i get the slider instance inside of that callable?

def changeit():
 #hiw to get the slider?

myslider = mset.UISliderFloat()
myslider.onChange = changeit

------

or is it even possible to use parameter within that callable?

Replies

  • AlainGalvan
    Offline / Send Message
    AlainGalvan polycounter lvl 6
    One option is to use a class, and to make myslider a member variable of that class. You can find a similar example of that in the Generate Primitives example in Toolbag, but here's an example:


     
    import mset
    
    class MyPlugin:
        window = mset.UIWindow("My Plugin")
        slider = None
    
        def sliderChangeCallback(self):
            print(self.slider.value)
    
        def render(self):
            self.window.clearElements()
            self.slider = mset.UISliderFloat(min=0.1, max=10, name="My New Slider")
            self.slider.onChange = lambda: self.sliderChangeCallback()
            self.window.addElement(self.slider)
            self.window.visible = True
    
        def __init__(self):
            self.render()
    
    MyPlugin()
    
  • goekbenjamin
    Offline / Send Message
    goekbenjamin polycounter lvl 6
    thanks alot AlainGalvan. this looks nice already.  :)
  • goekbenjamin
    Offline / Send Message
    goekbenjamin polycounter lvl 6
    btw how do i know when a UIColorPicker has changed its value? it has no onChange event afaik
Sign In or Register to comment.