Previous Thread  Next Thread

chat icon Python help

kemi242

Posted: Mon Sep 17, 2012 8:45 am
Joined: 17 Sep 2012
Posts: 1
Hi all!

I've written this little script which lets you move the active object around with console commands, to test out the capabilities of the Python API.
Code:
import bpy

ao = bpy.context.active_object

s = ''
while s != 'done':
    s = input('?:')
    if s == 'x+':
        ao.location.x += 1
    elif s == 'x-':
        ao.location.x -= 1
    elif s == 'y+':
        ao.location.y += 1
    elif s == 'y-':
        ao.location.y -= 1
    elif s == 'z+':
        ao.location.z += 1
    elif s == 'z-':
        ao.location.z -= 1
    elif s == 'reset':
        ao.location = [0, 0, 0]

However, my only problem is, that it only appends changes after the script has terminated, while I want something like an "interactive mode". I want to develop an addon that lets you use a WiiMote to capture 3D movement which can be used for animations, or just moving objects around (and of course it would be something constantly running and looking for input).
Any ideas?
Reply with quote


CoDEmanX

Posted: Mon Sep 17, 2012 1:37 pm
Joined: 05 Apr 2009
Posts: 894
integrating new blender input devices such as a wiimote is something, which should be coded in c/c++

with python, the only way to run something interactively is a modal operator (see code templates in text editor)

you can also react on certain events by using bpy.app.handlers, but it's pretty limited

you should not try to thread a python script, to keep blender running normal while a py script does changes to blender data in the background. This is not officially supported and will crash blender sooner or later.
_________________
I'm sitting, waiting, wishing, building Blender in superstition...
Reply with quote


 
Jump to:  
Powered by phpBB © 2001, 2005 phpBB Group