Hello,
Im fairly new to python and blender and have a little question. Im trying to create a slider that will move an object (e.g a sphere) along the x axis. The code I have so far, rather than moving the original object along, just creates a new one at the new x co-od. I tried using the getcurrent scene function to select the sphere but that didnt work either. Any suggestions or points in the right direction would be most appreciated!
Thanks!
Mel
import Blender
from Blender import *
sliderx = Draw.Create(1)
def MakeSphere():
me = Mesh.Primitives.Icosphere()
myObj = Object.New('Mesh')
myObj.link(me)
sc = Scene.GetCurrent()
sc.link(myObj)
myObj.LocX = myObj.LocX + sliderx.val
EV_BT_CANCEL = 2
EV_SL_X = 1
line = [None, None, None, None, None, None, None, None, None, None]
line[0] = 5
line[1] = 50
def draw_gui():
global sliderx
sliderx = Draw.Slider("X: ", EV_SL_X, 5, line[1], 100, 25, sliderx.val, 0.00, 10, 1, "X cood")
Draw.PushButton("cancel", EV_BT_CANCEL, 80, line[0], 60, 25, "cancel")
def event(event, val):
if event == Draw.ESCKEY or event == Draw.QKEY:
stop = Draw.PupMenu("OK?%t|Stop the script")
if stop == 1:
Draw.Exit()
if event == Draw.CKEY:
make = Draw.PupMenu("create sphere?%t|Construct the sphere")
if make == 1:
MakeSphere()
Blender.Redraw()
if not val:
if event in [Draw.LEFTMOUSE, Draw.MIDDLEMOUSE, Draw.RIGHTMOUSE]:
MakeSphere()
Blender.Redraw()
def button_event(evt):
if evt==EV_BT_CANCEL:
Draw.Exit()
Draw.Register(draw_gui, event, button_event)
Thank you both very much! I now see where I was going wrong with selecting the object.
Just a follow up question, does anyone know if there is a way to make the move with the slider continuous using the redraw function? As in rather than moving the slider to 8 and the object move there, have it move with the slider as it goes to 8? Or is that not possible?
The tenth parameter in the slider function is the realtime parameter [1]. In the script I posted it should already do what you want, but I just tested it and it doesn’t seem to work.
Perhaps it’s a good idea to start a new thread for your question.