Discussion:
[Bf-python] Blenders Python API as Python Extension
Glen Fletcher
2015-05-17 09:02:54 UTC
Permalink
I'm currently doing my PhD in plasmonics at UTS, we often need to create
code to create and manipulate complex 3D structure to feed into other
modeling software. This is a problem that is difficult due to the lack of
good libraries for manipulating a 3D environment.

In our code we use python + scientific libraries: numpy, scipy, matplotlib

I have also done 3d modeling as a hobby and use blender for this, I
understand from the blender manual that the object mapliculation functions
are exposed to the blender API such that any operations I perform in the
GUI could be performed by a python script thats run by blender.

What I'm interested in doing is compiling the blender API as a python
extension module that we could import in to python allowing the use of
blender function when creating 3D structure, and importing/exporting of
common 3D formats.

In this regard I have several questions.

1) Is this possible with out modifying the source code?
2) Are there any project that all ready expose blender API in such a way
3) What sort of integration with numpy arrays/buffer interface is possible
a) Get Array of faces/vertices suitable for use with matplotlib 3D plotting.
b) Apply operation of numpy array to find return Boolean map of enclosed
points
4) Am I able to get assistance from the Blender Development Team in
Exposing this API
5) Is it possible to support both python 2.7 and 3.x

I believe if such extenstion module was published as part of the blender
project it would find wide usage in scientific applications, and hope you
can assist me in this task.

Thank You.

Glen Fletcher
Jenny
2015-05-17 14:21:22 UTC
Permalink
Hi Glen,
Post by Glen Fletcher
1) Is this possible with out modifying the source code?
Have you taken a look at
http://wiki.blender.org/index.php/User%3aIdeasman42/BlenderAsPyModule ?

I'm not sure how up-to-date these instructions are, but it suggests a
way to build bpy as a Python module.
Post by Glen Fletcher
2) Are there any project that all ready expose blender API in such a way
There are plenty of scripts that use bpy from within Blender. I don't
know of any that use it as a standalone Python module.

There's also the possibility of running Blender headless if you want to
pipe things around.

http://wiki.blender.org/index.php/Doc:2.4/Manual/Render/Command_Line
Post by Glen Fletcher
3) What sort of integration with numpy arrays/buffer interface is possible
a) Get Array of faces/vertices suitable for use with matplotlib 3D plotting.
If you're dealing with meshes in Blender, you can definitely export a
list of their faces and vertices.
http://www.blender.org/api/blender_python_api_2_74_0/bpy.types.Mesh.html
Post by Glen Fletcher
b) Apply operation of numpy array  to find return Boolean map of enclosed points
If you're talking about matrix operations, Blender has its own mathutils
that supports matrices.
http://www.blender.org/api/blender_python_api_2_74_0/mathutils.html
If you really want to use numpy arrays, you might have to convert the
list of points into a numpy array first.
Post by Glen Fletcher
4) Am I able to get assistance from the Blender Development Team in Exposing this API
5) Is it possible to support both python 2.7 and 3.x
If you're talking about the bpy, it only supports Python 3.x. If your
only dependencies are numpy, scipy, and matplotlib, I believe they are
all Python 3 compatible.

Anyone else feel free to chime in.

Good luck,
Jenny
Christopher Barry
2015-05-17 19:48:52 UTC
Permalink
On Sun, 17 May 2015 19:02:54 +1000
Post by Glen Fletcher
I'm currently doing my PhD in plasmonics at UTS, we often need to
create code to create and manipulate complex 3D structure to feed into
other modeling software. This is a problem that is difficult due to
the lack of good libraries for manipulating a 3D environment.
In our code we use python + scientific libraries: numpy, scipy,
matplotlib
I have also done 3d modeling as a hobby and use blender for this, I
understand from the blender manual that the object mapliculation
functions are exposed to the blender API such that any operations I
perform in the GUI could be performed by a python script thats run by
blender.
What I'm interested in doing is compiling the blender API as a python
extension module that we could import in to python allowing the use of
blender function when creating 3D structure, and importing/exporting of
common 3D formats.
In this regard I have several questions.
1) Is this possible with out modifying the source code?
2) Are there any project that all ready expose blender API in such a
way 3) What sort of integration with numpy arrays/buffer interface is
possible a) Get Array of faces/vertices suitable for use with
matplotlib 3D plotting. b) Apply operation of numpy array to find
return Boolean map of enclosed points
4) Am I able to get assistance from the Blender Development Team in
Exposing this API
5) Is it possible to support both python 2.7 and 3.x
I believe if such extenstion module was published as part of the
blender project it would find wide usage in scientific applications,
and hope you can assist me in this task.
Thank You.
Glen Fletcher
Are you familiar with PythonOCC[1] / OpenCascade[2]?

[1] http://www.pythonocc.org/
[2] http://www.opencascade.org/getocc/download/loadocc/

--
Regards,
Christopher Barry

Random geeky fortune:
Airplanes are interesting toys but of no military value.
-- Marechal Ferdinand Foch, Professor of Strategy,
Ecole Superieure de Guerre
Marc Dion
2015-05-18 09:37:05 UTC
Permalink
There's a template for exporting data to simple generic arrays that is easy
to work with at the following site. http://ksolek.fm.interiowo.pl/Blender/

You may also want to check out #blendercoders and #blenderpython on
irc.freenode.net

On Sun, May 17, 2015 at 12:48 PM, Christopher Barry <
Post by Christopher Barry
On Sun, 17 May 2015 19:02:54 +1000
Post by Glen Fletcher
I'm currently doing my PhD in plasmonics at UTS, we often need to
create code to create and manipulate complex 3D structure to feed into
other modeling software. This is a problem that is difficult due to
the lack of good libraries for manipulating a 3D environment.
In our code we use python + scientific libraries: numpy, scipy, matplotlib
I have also done 3d modeling as a hobby and use blender for this, I
understand from the blender manual that the object mapliculation
functions are exposed to the blender API such that any operations I
perform in the GUI could be performed by a python script thats run by
blender.
What I'm interested in doing is compiling the blender API as a python
extension module that we could import in to python allowing the use of
blender function when creating 3D structure, and importing/exporting of
common 3D formats.
In this regard I have several questions.
1) Is this possible with out modifying the source code?
2) Are there any project that all ready expose blender API in such a
way 3) What sort of integration with numpy arrays/buffer interface is
possible a) Get Array of faces/vertices suitable for use with
matplotlib 3D plotting. b) Apply operation of numpy array to find
return Boolean map of enclosed points
4) Am I able to get assistance from the Blender Development Team in
Exposing this API
5) Is it possible to support both python 2.7 and 3.x
I believe if such extenstion module was published as part of the
blender project it would find wide usage in scientific applications,
and hope you can assist me in this task.
Thank You.
Glen Fletcher
Are you familiar with PythonOCC[1] / OpenCascade[2]?
[1] http://www.pythonocc.org/
[2] http://www.opencascade.org/getocc/download/loadocc/
--
Regards,
Christopher Barry
Airplanes are interesting toys but of no military value.
-- Marechal Ferdinand Foch, Professor of Strategy,
Ecole Superieure de Guerre
_______________________________________________
Bf-python mailing list
http://lists.blender.org/mailman/listinfo/bf-python
Loading...