[Bf-python] Embedding Blender - XEmbed protocol

Goat Man goatman.py at gmail.com
Thu Jul 22 03:28:08 CEST 2010


Celery looks like it is mature and has many features, i'm going to look at
it more. Thanks Stuart.

For maximum speed and simplicity, i have a minimal wrapper that can interact
with Blender's python API in a very limited way.  If you can live with one
function call per line, and only a single variable returned from functions,
source code is here:

http://pastebin.com/iPjBpD9P

<http://pastebin.com/iPjBpD9P>you can create a proxy module "bpy" in the
process outside of Blender, operations on bpy get stored in an string that
can be executed later in Blender.  For example:

bpy.ops
bpy.data.objects
v = bpy.nothing.nowhere.nohow(1,2,3,"hi", True, {'dict-test':1}, key="test"
)
bpy.new.func(v.x)

this gets converted into a simple string:
bpy.ops;bpy.data.objects;var0 =
bpy.nothing.nowhere.nohow(1,2,3,"hi",True,{'dict-test': 1},key="test",);var1
= bpy.new.func(var0.x,);


While we wait for the scriptlinks replacement, if you need Blender2.5 to
talk to another process, the only way i have found is to start it from the
command line, setting it into playback mode, and on the redraw event listen
to the pipe.  See below.

import os,sys, bpy, select
bpy.ops.screen.animation_play('EXEC_DEFAULT')

def draw_callback( area, region ):
rlist,wlist,xlist = select.select( [sys.stdin], [], [], 0.001 )
if rlist:
data = rlist[0].readline()
print( '>>', len(data) )
exec( data )
for area in bpy.context.window.screen.areas:
print(area.type)
if area.type == 'VIEW_3D':
area.tag_redraw()
for reg in area.regions:
print( '\tregion: ', reg.type )
if reg.type == 'WINDOW':
print( 'adding callback' )
reg.callback_add(draw_callback, (area,reg), 'POST_PIXEL')



On Wed, Jul 21, 2010 at 2:57 AM, Stuart Axon <stuaxo2 at yahoo.com> wrote:

> Something like celery might be a way of exporting the api to another python
> server.
>
> S++
>
>
> *From:* Goat Man <goatman.py at gmail.com>
> *To:* Blender Foundation Python list <bf-python at blender.org>
> *Sent:* Tue, July 20, 2010 2:11:49 AM
> *Subject:* [Bf-python] Embedding Blender - XEmbed protocol
>
> I didn't realize Blender can be embedded in a PyGTK window using
> gtk.Socket.
> Its an ugly hack to use the command line "xwininfo" to get the xid, it
> would be better if Blender printed on the command line its windowID or was
> available in the python API.
> This demo works most of the time, if the window loses focus then mouse
> clicking stops working, but keyboard and the mouse wheel seems to always
> work.
>
> http://pastebin.com/vYtJmmAC
>
> To make this useful we need a way to run a python loop in blender that
> talks on a socket or pipe to the parent process running pygtk.
>
>
>
> _______________________________________________
> Bf-python mailing list
> Bf-python at blender.org
> http://lists.blender.org/mailman/listinfo/bf-python
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.blender.org/pipermail/bf-python/attachments/20100722/644da409/attachment.html>


More information about the Bf-python mailing list