<html><body><div style="color:#000; background-color:#fff; font-family:arial, helvetica, sans-serif;font-size:12pt"><div><span>i have been successful making a bridge between two blenders , or 1 cpython 3.2 and blender , or 1 cpython 2.7 and blender or pypy 1.9 and blender . Its part of my project Ephestos, a new blender gui API and a visual coding enviroment in pure python</span></div><div><span><br></span></div><div><span>you can see  my client and server here </span></div><div><span><br></span></div><div><span><a href="https://github.com/kilon/Ephestos/tree/master/proteas">https://github.com/kilon/Ephestos/tree/master/proteas</a> <br></span></div><div><span><br></span></div><div><span>my server is locked waiting for reply, but that is to be fixed by putting it in its own process with the multithreading module , its still WIP but via my tests calling blender python function seems to work
 ok</span></div><div><span><br></span></div><div><span>the goal is not only to make any blender talk to each other but also for any language able to use blender python and blender python to use any programming language and any library there are available for that language. </span></div><div><span><br></span></div><div><span>I am using the XMLRPC protocol, but its basically using sockets  </span></div><div><span><br></span></div><div><span><br></span></div><div><br></div>  <div style="font-family: arial, helvetica, sans-serif; font-size: 12pt; "> <div style="font-family: 'times new roman', 'new york', times, serif; font-size: 12pt; "> <div dir="ltr"> <font size="2" face="Arial"> <hr size="1">  <b><span style="font-weight:bold;">From:</span></b> Kabir Soorya <phantom982002@gmail.com><br> <b><span style="font-weight: bold;">To:</span></b> bf-python@blender.org <br> <b><span style="font-weight: bold;">Sent:</span></b> Thursday, 5 July 2012,
 6:37<br> <b><span style="font-weight: bold;">Subject:</span></b> [Bf-python] Using a Modal Operator and Nonblocking Sockets to Control Blender from an External Python Shell<br> </font> </div> <br><div id="yiv636448106">Hi,<div><br></div><div>I'm trying to find a good way to control Blender from an external Python shell. I've spent a lot of time looking at past attempts and see that most haven't gone anywhere, as Blender's architecture seems to make this difficult. I tried to just have Python's InteractiveInterpreter class fed from a socket, but unfortunately Blender locks up completely while listening on the socket -- so it's not even able to come back into focus when I Alt-Tab to it. That's not really ideal, and so after reading the docs, it seems like the right way to do this is to have a modal operator on an event timer repeatedly grab input from a nonblocking socket, and feed *that* into InteractiveInterpreter. Unfortunately, the only code I've been
 able to cobble together for event timers seems to make blender unresponsive, and cause it to crash horribly. I've attached the code below, if anyone knows what's going on -- or has a better way to connect Blender to an external Python, I'd love to hear your thoughts. </div>
<div><br></div><div><br></div><blockquote style="margin:0 0 0 40px;border:none;padding:0px;"><div><div><font face="courier new, monospace">import bpy</font></div></div><div><div><font face="courier new, monospace"><br></font></div>
</div><div><div><font face="courier new, monospace">class ModalOperator(bpy.types.Operator):</font></div></div><div><div><font face="courier new, monospace">    '''Operator which runs its self from a timer.'''</font></div>
</div><div><div><font face="courier new, monospace">    bl_idname = "wm.modal_operator"</font></div></div><div><div><font face="courier new, monospace">    bl_label = "Vertex Operator"</font></div></div>
<div><div><font face="courier new, monospace"><br></font></div></div><div><div><font face="courier new, monospace">    _timer = None</font></div></div><div><div><font face="courier new, monospace"><br></font></div></div><div>
<div><font face="courier new, monospace">    def modal(self, context, event):</font></div></div><div><div><font face="courier new, monospace">        print(event.type)</font></div></div><div><div><font face="courier new, monospace">        if event.type == 'ESC':</font></div>
</div><div><div><font face="courier new, monospace">            print("FINISHED")</font></div></div><div><div><font face="courier new, monospace">            context.window_manager.event_timer_remove(self._timer)</font></div>
</div><div><div><font face="courier new, monospace">            return {'FINISHED'}</font></div></div><div><div><font face="courier new, monospace">    <span class="yiv636448106Apple-tab-span" style="white-space:pre;">    </span></font></div>
</div><div><div><font face="courier new, monospace">        if event.type == 'TIMER':</font></div></div><div><div><font face="courier new, monospace">            self.execute(context)</font></div></div><div><div><font face="courier new, monospace">            return {'RUNNING_MODAL'}</font></div>
</div><div><div><font face="courier new, monospace"><br></font></div></div><div><div><font face="courier new, monospace">    def execute(self, context):</font></div></div><div><div><font face="courier new, monospace">        print("EXC")</font></div>
</div><div><div><font face="courier new, monospace">        bpy.ops.object.mode_set(mode='EDIT')</font></div></div><div><div><font face="courier new, monospace">        context.window_manager.modal_handler_add(self)</font></div>
</div><div><div><font face="courier new, monospace">        self._timer = context.window_manager.event_timer_add(0.1, context.window)</font></div></div><div><div><span class="yiv636448106Apple-tab-span" style="white-space:pre;"><font face="courier new, monospace">  </font></span></div>
</div><div><div><font face="courier new, monospace">bpy.utils.register_class(ModalOperator)</font></div></div><div><div><font face="courier new, monospace">bpy.ops.wm.modal_operator('INVOKE_DEFAULT')</font></div></div>
</blockquote><div><br></div>
</div><br>_______________________________________________<br>Bf-python mailing list<br><a ymailto="mailto:Bf-python@blender.org" href="mailto:Bf-python@blender.org">Bf-python@blender.org</a><br><a href="http://lists.blender.org/mailman/listinfo/bf-python" target="_blank">http://lists.blender.org/mailman/listinfo/bf-python</a><br><br><br> </div> </div>  </div></body></html>