Hi, I’m trying to generate a GUI with a variable number of sliders. The amount of sliders depends on the number of bones on an armature that are named on a specific way. This is, if ANY bone starts with “SLI” a slider should be created for it.
Now I got something that seems to work partially…
import Blender from Blender import Draw, Scene, Window, Armature, Mathutils g_slider =  # slider objects to show up in GUI sliders =  # bone names to create sliders after #Some constants: EVENT = 400 BASE_X = 10 BASE_Y = 10 SLI_width = 300 SLI_height = 20 DY = 0 INIT = 0 def DrawSlider(slider): # returns a Slider Object (or that's what it is supposed to do) global EVENT, BASE_X, DY, BASE_Y, SLI_width, SLI_height Y = BASE_Y + DY * 40 newslider = Draw.Slider(slider, EVENT+1, BASE_X, Y, SLI_width,SLI_height,0.0,0.0,1.0) return newslider def gui_event(evt, val): # the function to handle input events if evt == Draw.ESCKEY: Draw.Exit() # exit when user presses ESC return def button_event(evt): # the function to handle Draw Button events #crappy sample code... not really important if evt == 400: print "You pressed one slider." elif evt==401: print "you pressed other slider" def gui_draw(): global sliders, g_slider, INIT, DY if INIT == 0: # For each bone starting with SLI it creates a slider for s in sliders: DY = DY + 1 gui_slider = DrawSlider(s) g_slider.append(gui_slider) INIT = 1 print INIT #Draw.Redraw(1) if INIT == 0: scene = Scene.GetCurrent() active = scene.objects.active active_data = active.getData() if type(active_data) == Blender.Types.ArmatureType: if Window.PoseMode() == True: armature_object = active armature_data = armature_object.getData() p = armature_object.getPose() print p.bones for key in p.bones.keys(): if key[:3] == "SLI": #if 3 first characters... sliders.append(key) # appends bone name to a list Draw.Register(gui_draw, gui_event, button_event)
The problem with this code is that as soon as you click on a slider the GUI is cleaned and the sliders are gone. My question is how can I keep the sliders in the GUI ? I suppose that what is going on is that I’m failing at creating pointers to the slider objects… anybody knows ?
Thanks in advance !