Python help

Compiling, libraries, modules, coding guidelines and porting

Moderators: jesterKing, stiv

Post Reply
Posts: 0
Joined: Mon Sep 17, 2012 9:34 am

Python help

Post by kemi242 » Mon Sep 17, 2012 9:45 am

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: Select all

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?

Posts: 0
Joined: Sun Apr 05, 2009 7:42 pm
Location: Germany

Post by CoDEmanX » Mon Sep 17, 2012 2:37 pm

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, 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...

Post Reply