lp:~diresu/blender/blender-command-port-002

Created by Dietrich Bollmann on 2009-10-28 and last modified on 2010-09-04

This is a branch of Blender (http://www.blender.org/) which implements a Python Command Port for Blender 2.5:

Blender can be started in server mode and Clients can connect and send Python commands via the command port to the server.

For more detailed information concerning older versions (2.4) see http://formgames.org/blender/command-port/ - I have to update the page for Blender 2.5 some day...

NOTES:

  - This branch contains the Blender Command Port branch from version 2.5 up.
  - For older (and working) versions (Blender 2.4*) see https://code.launchpad.net/~diresu/blender/blender-command-port

EXAMPLE:

# starting the server:
blender -p 10 10 800 600 --command-port 6789

> found bundled python: /home/dietrich/blendev/bazaar/blender/working/branches/blender-command-port/install/linux2/.blender/python
> Starting the Blender command port - listening on port 6789.

# starting the python client shell
blash --port 6789

> This is Blash - the GNU BLender-Again SHell :)
> Connection to Blender Server established. (IP address: 127.0.0.1, port: 6789)

import bpy

# adding a monkey
bpy.ops.mesh.primitive_monkey_add()
bpy.ops.wm.redraw()

# adding another monkey
bpy.ops.mesh.primitive_monkey_add(view_align = False, enter_editmode = False, location = (0, 0, 0), rotation = (0, 0, 0))
bpy.ops.wm.redraw()

# adding a cube
bpy.ops.mesh.primitive_cube_add()
bpy.ops.wm.redraw()

# adding a pyramid
vertices = [1, 1, 0, -1, 1, 0, -1, -1, 0, 1, -1, 0, 0, 0, 1.27]
faces = [0, 3, 2, 1, 0, 1, 4, 0, 1, 2, 4, 0, 2, 3, 4, 0, 3, 0, 4, 0]
mesh = bpy.data.meshes.new("Pyramid")
mesh.vertices.add(len(vertices) // 3)
mesh.faces.add(len(faces) // 4)
mesh.vertices.foreach_set("co", vertices)
mesh.faces.foreach_set("vertices_raw", faces)
mesh.update()
pyramid = bpy.data.objects.new("Pyramid", mesh)
bpy.context.scene.objects.link(pyramid)
bpy.ops.wm.redraw()

# quitting the python client shell
quit

NOTES:

  - The operator bpy.ops.wm.redraw() redraws the blender window.
    It currently only exist in the blender 2.5 command port branch.

TODO:

  - If a better way is found for setting the context in function
    run_python() (file: blender/source/creator/creator.c)
    adapt the command port code also!

Get this branch:
bzr branch lp:~diresu/blender/blender-command-port-002
Only Dietrich Bollmann can upload to this branch. If you are Dietrich Bollmann please log in for upload directions.

Branch merges

Related bugs

Related blueprints

Branch information

Owner:
Dietrich Bollmann
Project:
Blender
Status:
Development

Recent revisions

15549. By Dietrich Bollmann on 2010-09-04

Added a patch by Marc Weber implementing the installation of 'blash' via cmake.

15548. By Dietrich Bollmann on 2010-09-02

Added "A cmake patch for command port" by Marc Weber.

15547. By Dietrich Bollmann on 2010-08-29

Made the 'blash' build code work with the code updated to revision 31636.

15546. By Dietrich Bollmann on 2010-08-29

Update to state of blender repository from 2010-08-28 revision 31636.

15545. By Dietrich Bollmann on 2010-07-24

Added an operator to redraw the blender GUI: bpy.ops.wm.redraw().

This is meant as a substitute of Blender 2.4*'s Redraw() function...

15544. By Dietrich Bollmann on 2010-07-23

Made the command port and the command port client compile and work again.

15543. By Dietrich Bollmann on 2010-07-23

Update to state of blender repository from 2010-07-23 revision 30644.

15542. By Dietrich Bollmann on 2010-04-27

Update to state of blender repository from 2010-04-27 revision 28457.

15541. By Dietrich Bollmann on 2010-04-01

* Fixed a bug which caused Python to interpret a multiline input
as complete even whithout a terminating empty input line.

The bug was caused by

  - the command port clients terminating every command string with a
    newline character
  - the 'compile_command()' function of the 'codeop' module not
    expecting a terminating newline character and interpreting it as
    a terminating empty line :)

A wrapper function which temporarily overwrites the last newline
character with a null character terminating the string solved the
issue.

Test:

Before:

>>> for i in range(3):
... print(i)
0
1
2
...
0
1
2
>>>

After:

>>> for i in range(3):
... print(i)
...
0
1
2
>>>

15540. By Dietrich Bollmann on 2010-03-26

* Finally the blender 2.5 command port works again :)

Fixed the blender context error by using the hack from function
run_python() (file: blender/source/creator/creator.c) and borrowing
the bpy.context.scene from the first window in the wm window queue...

Example:

# starting the server:

blender -p 10 10 800 600 --command-port 6789

> found bundled python: /home/dietrich/blendev/bazaar/blender/working/branches/blender-command-port/install/linux2/.blender/python
> Starting the Blender command port - listening on port 6789.

# starting the client:

blash --port 6789

> This is Blash - the GNU BLender-Again SHell :)
> Connection to Blender Server established. (IP address: 127.0.0.1, port: 6789)

import bpy
bpy.ops.mesh.primitive_monkey_add(layer = [True]+[False]*31)

> {'FINISHED'}

bpy.ops.mesh.primitive_monkey_add(view_align = False, enter_editmode = False, location = (0, 0, 0), rotation = (0, 0, 0), layer = [True]+[False]*31)

> {'FINISHED'}

quit

> bye...

TODO:

  - To see the newly created mesh I currently have to cause a redraw
    of the GUI by moving the mouse over the blender window...
    ...Have to find a way to redraw the window from the bash shell.

  - When executing the following code, the result is printed twice
    (and probably the code is executed twice also...).

      | >>> for i in range(3):
      | ... print(i)
      | 0
      | 1
      | 2
      | ...
      | 0
      | 1
      | 2
      | >>>

  - If a better way is found for setting the context in function
    run_python() (file: blender/source/creator/creator.c)
    adapt the command port code also!

Branch metadata

Branch format:
Branch format 7
Repository format:
Bazaar repository format 2a (needs bzr 1.16 or later)
This branch contains Public information 
Everyone can see this information.